|
| 1 | +import type { Meta } from '@storybook/react'; |
| 2 | +import { useEffect } from 'react'; |
| 3 | +import { action } from '@storybook/addon-actions'; |
| 4 | +import WebComponentDocTemplate from '../../../../../../.storybook/docs/WebComponentDocTemplate.mdx'; |
| 5 | +import { webComponentDecorator } from '../../../../../design-system/src/components/web-components/storybook'; |
| 6 | +import './ds-simple-footer'; |
| 7 | + |
| 8 | +const meta: Meta = { |
| 9 | + title: 'Medicare/Web Components/ds-simple-footer', |
| 10 | + decorators: [webComponentDecorator], |
| 11 | + parameters: { |
| 12 | + theme: 'medicare', |
| 13 | + docs: { |
| 14 | + page: WebComponentDocTemplate, |
| 15 | + description: { |
| 16 | + component: |
| 17 | + 'For information about how and when to use this component, [refer to its full documentation page](https://design.cms.gov/components/footer/medicare-footer).', |
| 18 | + }, |
| 19 | + componentEvents: { |
| 20 | + 'ds-link-click-analytics': { |
| 21 | + description: 'A callback function triggered when the user clicks a link in the footer.', |
| 22 | + }, |
| 23 | + }, |
| 24 | + }, |
| 25 | + }, |
| 26 | + argTypes: { |
| 27 | + 'about-medicare-label': { |
| 28 | + description: 'Label for the "About" link.', |
| 29 | + control: 'text', |
| 30 | + defaultValue: { summary: 'About' }, |
| 31 | + }, |
| 32 | + 'nondiscrimination-label': { |
| 33 | + description: 'Label for the "Accessibility" link.', |
| 34 | + control: 'text', |
| 35 | + defaultValue: { summary: 'Accessibility' }, |
| 36 | + }, |
| 37 | + 'privacy-policy-label': { |
| 38 | + description: 'Label for the "Privacy policy" link.', |
| 39 | + control: 'text', |
| 40 | + defaultValue: { summary: 'Privacy policy' }, |
| 41 | + }, |
| 42 | + 'privacy-setting-label': { |
| 43 | + description: 'Label for the "Privacy setting" link.', |
| 44 | + control: 'text', |
| 45 | + defaultValue: { summary: 'Privacy setting' }, |
| 46 | + }, |
| 47 | + 'linking-policy-label': { |
| 48 | + description: 'Label for the "Linking policy" link.', |
| 49 | + control: 'text', |
| 50 | + defaultValue: { summary: 'Linking policy' }, |
| 51 | + }, |
| 52 | + 'using-this-site-label': { |
| 53 | + description: 'Label for the "Using this site" link.', |
| 54 | + control: 'text', |
| 55 | + defaultValue: { summary: 'Using this site' }, |
| 56 | + }, |
| 57 | + 'plain-writing-label': { |
| 58 | + description: 'Label for the "Plain writing" link.', |
| 59 | + control: 'text', |
| 60 | + defaultValue: { summary: 'Plain writing' }, |
| 61 | + }, |
| 62 | + 'website-info': { |
| 63 | + description: |
| 64 | + 'Text describing the website’s management and funding, typically displayed in the footer. Defaults to a standard message indicating CMS ownership.', |
| 65 | + control: 'text', |
| 66 | + defaultValue: { |
| 67 | + summary: |
| 68 | + 'A federal government website managed and paid for by the U.S. Centers for Medicare and Medicaid Services.', |
| 69 | + }, |
| 70 | + }, |
| 71 | + language: { |
| 72 | + description: |
| 73 | + "Language for the 'Privacy Setting' modal. See Tealium documentation for more information.", |
| 74 | + control: 'text', |
| 75 | + defaultValue: { summary: 'en' }, |
| 76 | + }, |
| 77 | + }, |
| 78 | +}; |
| 79 | + |
| 80 | +const Template = (args) => { |
| 81 | + useEffect(() => { |
| 82 | + const footer = document.querySelector('ds-simple-footer'); |
| 83 | + // Adding custom event listeners to open links in new tabs, allowing us to log and verify |
| 84 | + // the `ds-click-link-analytics` event in Storybook actions. |
| 85 | + const links = footer?.querySelectorAll('a'); |
| 86 | + links?.forEach((link) => { |
| 87 | + link.setAttribute('target', '_blank'); |
| 88 | + link.addEventListener('click', (e) => { |
| 89 | + e.preventDefault(); |
| 90 | + window.open(link.href, '_blank'); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + const handleAnalyticsEvent = (event: Event) => { |
| 95 | + const customEvent = event as CustomEvent; |
| 96 | + event.preventDefault(); |
| 97 | + action('ds-click-link-analytics')(customEvent); |
| 98 | + }; |
| 99 | + |
| 100 | + footer.addEventListener('ds-click-link-analytics', handleAnalyticsEvent); |
| 101 | + |
| 102 | + return () => { |
| 103 | + links?.forEach((link) => { |
| 104 | + link.removeEventListener('click', (e) => e.preventDefault()); |
| 105 | + }); |
| 106 | + footer.removeEventListener('ds-click-link-analytics', handleAnalyticsEvent); |
| 107 | + }; |
| 108 | + }, []); |
| 109 | + return <ds-simple-footer {...args}></ds-simple-footer>; |
| 110 | +}; |
| 111 | + |
| 112 | +export const Default = Template.bind({}); |
| 113 | + |
| 114 | +export default meta; |
0 commit comments