@cnamts/synapse 0.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/design-system-v3.d.ts +246 -0
  4. package/dist/design-system-v3.js +5425 -0
  5. package/dist/design-system-v3.umd.cjs +2 -0
  6. package/dist/style.css +1 -0
  7. package/package.json +104 -0
  8. package/src/assets/tokens.scss +500 -0
  9. package/src/components/Alert/Alert.mdx +36 -0
  10. package/src/components/Alert/Alert.stories.ts +115 -0
  11. package/src/components/Alert/Alert.vue +248 -0
  12. package/src/components/Alert/locales.ts +3 -0
  13. package/src/components/Alert/tests/Alert.spec.ts +105 -0
  14. package/src/components/Alert/tests/__snapshots__/Alert.spec.ts.snap +15 -0
  15. package/src/components/BackBtn/BackBtn.mdx +26 -0
  16. package/src/components/BackBtn/BackBtn.stories.ts +138 -0
  17. package/src/components/BackBtn/BackBtn.vue +60 -0
  18. package/src/components/BackBtn/locales.ts +3 -0
  19. package/src/components/BackBtn/tests/BackBtn.spec.ts +103 -0
  20. package/src/components/BackBtn/tests/__snapshots__/BackBtn.spec.ts.snap +9 -0
  21. package/src/components/BackToTopBtn/BackToTopBtn.mdx +52 -0
  22. package/src/components/BackToTopBtn/BackToTopBtn.stories.ts +188 -0
  23. package/src/components/BackToTopBtn/BackToTopBtn.vue +137 -0
  24. package/src/components/BackToTopBtn/config.ts +12 -0
  25. package/src/components/BackToTopBtn/locales.ts +3 -0
  26. package/src/components/BackToTopBtn/tests/BackToTopBtn.spec.ts +173 -0
  27. package/src/components/BackToTopBtn/tests/__snapshots__/BackToTopBtn.spec.ts.snap +17 -0
  28. package/src/components/Beta/beta.mdx +5 -0
  29. package/src/components/CopyBtn/CopyBtn.mdx +38 -0
  30. package/src/components/CopyBtn/CopyBtn.stories.ts +209 -0
  31. package/src/components/CopyBtn/CopyBtn.vue +103 -0
  32. package/src/components/CopyBtn/config.ts +17 -0
  33. package/src/components/CopyBtn/locales.ts +3 -0
  34. package/src/components/CopyBtn/tests/CopyBtn.spec.ts +99 -0
  35. package/src/components/CopyBtn/tests/__snapshots__/CopyBtn.spec.ts.snap +7 -0
  36. package/src/components/Deprecated/deprecated.mdx +5 -0
  37. package/src/components/DownloadBtn/DownloadBtn.mdx +94 -0
  38. package/src/components/DownloadBtn/DownloadBtn.stories.ts +211 -0
  39. package/src/components/DownloadBtn/DownloadBtn.vue +113 -0
  40. package/src/components/DownloadBtn/config.ts +13 -0
  41. package/src/components/DownloadBtn/tests/DownloadBtn.spec.ts +82 -0
  42. package/src/components/DownloadBtn/tests/__snapshots__/DownloadBtn.spec.ts.snap +17 -0
  43. package/src/components/DownloadBtn/tests/data/filePromise.ts +53 -0
  44. package/src/components/DownloadBtn/tests/data/test.json +0 -0
  45. package/src/components/FranceConnectBtn/FranceConnectBtn.mdx +34 -0
  46. package/src/components/FranceConnectBtn/FranceConnectBtn.stories.ts +92 -0
  47. package/src/components/FranceConnectBtn/FranceConnectBtn.vue +154 -0
  48. package/src/components/FranceConnectBtn/locales.ts +6 -0
  49. package/src/components/FranceConnectBtn/tests/FranceConnectBtn.spec.ts +62 -0
  50. package/src/components/FranceConnectBtn/tests/__snapshots__/FranceConnectBtn.spec.ts.snap +36 -0
  51. package/src/components/LangBtn/LangBtn.mdx +37 -0
  52. package/src/components/LangBtn/LangBtn.stories.ts +147 -0
  53. package/src/components/LangBtn/LangBtn.vue +167 -0
  54. package/src/components/LangBtn/config.ts +17 -0
  55. package/src/components/LangBtn/locales.ts +3 -0
  56. package/src/components/LangBtn/tests/Config.spec.ts +24 -0
  57. package/src/components/LangBtn/tests/LangBtn.spec.ts +283 -0
  58. package/src/components/LangBtn/tests/__snapshots__/LangBtn.spec.ts.snap +11 -0
  59. package/src/components/LangBtn/types.d.ts +7 -0
  60. package/src/components/NotificationBar/NotificationBar.mdx +94 -0
  61. package/src/components/NotificationBar/NotificationBar.stories.ts +366 -0
  62. package/src/components/NotificationBar/NotificationBar.vue +296 -0
  63. package/src/components/NotificationBar/options.ts +15 -0
  64. package/src/components/NotificationBar/tests/NotificationBar.spec.ts +332 -0
  65. package/src/components/NotificationBar/tests/__snapshots__/NotificationBar.spec.ts.snap +7 -0
  66. package/src/components/NotificationBar/types.ts +7 -0
  67. package/src/components/PageContainer/PageContainer.mdx +29 -0
  68. package/src/components/PageContainer/PageContainer.stories.ts +115 -0
  69. package/src/components/PageContainer/PageContainer.vue +68 -0
  70. package/src/components/PageContainer/tests/PageContainer.spec.ts +56 -0
  71. package/src/components/PageContainer/tests/__snapshots__/PageContainer.spec.ts.snap +7 -0
  72. package/src/components/SkipLink/SkipLink.mdx +55 -0
  73. package/src/components/SkipLink/SkipLink.stories.ts +70 -0
  74. package/src/components/SkipLink/SkipLink.vue +79 -0
  75. package/src/components/SkipLink/locales.ts +3 -0
  76. package/src/components/SkipLink/tests/__snapshots__/skipLink.spec.ts.snap +3 -0
  77. package/src/components/SkipLink/tests/skipLink.spec.ts +46 -0
  78. package/src/components/index.ts +8 -0
  79. package/src/composables/useCustomizableOptions.ts +23 -0
  80. package/src/designTokens/bootstrapColors.md +66 -0
  81. package/src/designTokens/cnamColors.md +193 -0
  82. package/src/designTokens/index.ts +15 -0
  83. package/src/designTokens/tokens/bootstrap/bootstrapColors.ts +158 -0
  84. package/src/designTokens/tokens/bootstrap/bootstrapLightTheme.ts +22 -0
  85. package/src/designTokens/tokens/cnam/cnamColors.ts +171 -0
  86. package/src/designTokens/tokens/cnam/cnamContextual.ts +58 -0
  87. package/src/designTokens/tokens/cnam/cnamLightTheme.ts +90 -0
  88. package/src/designTokens/tokens/cnam/cnamSemantic.ts +87 -0
  89. package/src/designTokens/tokens/json/contextual-tokens.json +156 -0
  90. package/src/designTokens/tokens/json/primitives.json +209 -0
  91. package/src/designTokens/tokens/json/semantic.json +120 -0
  92. package/src/designTokens/utils/convertGaps.ts +11 -0
  93. package/src/designTokens/utils/convertSemanticsToken.ts +32 -0
  94. package/src/designTokens/utils/createFlattenTheme.ts +19 -0
  95. package/src/designTokens/utils/index.ts +4 -0
  96. package/src/main.ts +2 -0
  97. package/src/services/NotificationService.ts +27 -0
  98. package/src/stories/Fondamentaux/Accessibilite/Accessibilite.mdx +52 -0
  99. package/src/stories/Fondamentaux/Accessibilite/Accessibilite.stories.ts +36 -0
  100. package/src/stories/Fondamentaux/Accessibilite/AccessibiliteItems.ts +706 -0
  101. package/src/stories/Fondamentaux/Accessibilite/constants/ExpertiseLevelEnum.ts +5 -0
  102. package/src/stories/Fondamentaux/Accessibilite/constants/RGAALevelEnum.ts +4 -0
  103. package/src/stories/Fondamentaux/EcoConception/EcoConception.mdx +24 -0
  104. package/src/stories/Fondamentaux/EcoConception/Econception.stories.ts +30 -0
  105. package/src/stories/Fondamentaux/EcoConception/ecoDesignItems.ts +55 -0
  106. package/src/stories/GuideDuDev/CommentContribuer.mdx +22 -0
  107. package/src/stories/GuideDuDev/components.stories.ts +23 -0
  108. package/src/stories/GuideDuDev/moduleDeNotification.mdx +182 -0
  109. package/src/stories/GuideDuDev/vuetifyOptions.mdx +72 -0
  110. package/src/stories/Guidelines/Colors.mdx +220 -0
  111. package/src/stories/Guidelines/CustomisationEtThemes.mdx +3 -0
  112. package/src/stories/Guidelines/Introduction.mdx +35 -0
  113. package/src/stories/Guidelines/Typo.mdx +53 -0
  114. package/src/stories/Home/Accueil.mdx +7 -0
  115. package/src/stories/Home/PolitiqueDeConfidentialite.mdx +4 -0
  116. package/src/stories/Home/synapse.webp +0 -0
  117. package/src/temp/TestA11y.vue +14 -0
  118. package/src/temp/TestComponent.vue +37 -0
  119. package/src/temp/TestDTComponent.vue +93 -0
  120. package/src/temp/customizableOptions.vue +18 -0
  121. package/src/temp/gridsTests.vue +54 -0
  122. package/src/temp/options.json +5 -0
  123. package/src/types/vuetifyTypes.ts +3 -0
  124. package/src/utils/convertToUnit/index.ts +16 -0
  125. package/src/utils/convertToUnit/test/convertToUnit.spec.ts +32 -0
  126. package/src/utils/functions/copyToClipboard/index.ts +38 -0
  127. package/src/utils/functions/copyToClipboard/tests/copyToClipboard.spec.ts +104 -0
  128. package/src/utils/functions/downloadFile/index.ts +37 -0
  129. package/src/utils/functions/downloadFile/tests/downloadFile.spec.ts +69 -0
  130. package/src/utils/functions/downloadFile/types.ts +1 -0
@@ -0,0 +1,209 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3'
2
+ import CopyBtn from './CopyBtn.vue'
3
+ import { VIcon } from 'vuetify/components'
4
+ import { mdiContentDuplicate } from '@mdi/js'
5
+
6
+ const duplicateIcon = mdiContentDuplicate
7
+
8
+ const meta = {
9
+ title: 'Components/CopyBtn',
10
+ component: CopyBtn,
11
+ parameters: {
12
+ layout: 'fullscreen',
13
+ controls: { exclude: ['copy'] },
14
+ },
15
+ argTypes: {
16
+ ariaLabel: {
17
+ control: { type: 'text' },
18
+ default: 'copy-btn',
19
+ },
20
+ ariaOwns: {
21
+ control: { type: 'text' },
22
+ default: 'copy-btn',
23
+ },
24
+ textToCopy: {
25
+ control: { type: 'text' },
26
+ default: 'test',
27
+ },
28
+ hideTooltip: {
29
+ control: { type: 'boolean' },
30
+ default: false,
31
+ },
32
+ tooltipDuration: {
33
+ control: { type: 'number' },
34
+ default: 2000,
35
+ },
36
+ vuetifyOptions: {
37
+ control: { type: 'object' },
38
+ default: () => ({
39
+ menu: {
40
+ location: 'end center',
41
+ offset: 16,
42
+ zIndex: 8,
43
+ contentClass: 'vd-copy-tooltip-menu text-white text-body-2 ml-2',
44
+ },
45
+ btn: {
46
+ icon: true,
47
+ variant: 'text',
48
+ density: 'comfortable',
49
+ },
50
+ icon: {
51
+ color: 'grey-darken-20',
52
+ },
53
+ }),
54
+ },
55
+ },
56
+ } satisfies Meta<typeof CopyBtn>
57
+
58
+ export default meta
59
+
60
+ type Story = StoryObj<typeof meta>
61
+
62
+ export const Default: Story = {
63
+ args: {
64
+ ariaLabel: 'Copier le numéro de patient',
65
+ ariaOwns: 'copy-btn-1',
66
+ textToCopy: '1970756541',
67
+ hideTooltip: false,
68
+ tooltipDuration: 2000,
69
+ vuetifyOptions: {
70
+ menu: {
71
+ location: 'end center',
72
+ offset: 16,
73
+ zIndex: 8,
74
+ contentClass: 'vd-copy-tooltip-menu text-white text-body-2 ml-2',
75
+ },
76
+ btn: {
77
+ icon: true,
78
+ variant: 'text',
79
+ density: 'comfortable',
80
+ },
81
+ icon: {
82
+ color: 'grey-darken-20',
83
+ },
84
+ },
85
+ },
86
+ render: (args) => {
87
+ return {
88
+ components: { CopyBtn },
89
+ setup() {
90
+ return { args }
91
+ },
92
+ template: `
93
+ <div class="d-flex flex-wrap align-center pa-4">
94
+ <p class="mb-0 mr-1">
95
+ Patient n°<b>1970756541</b>
96
+ </p>
97
+
98
+ <CopyBtn
99
+ label="Copier le numéro de patient"
100
+ text-to-copy="1970756541"
101
+ :hide-tooltip="args.hideTooltip"
102
+ :vuetify-options="args.vuetifyOptions"
103
+ />
104
+ </div>
105
+ `,
106
+ }
107
+ },
108
+ }
109
+
110
+ export const NoTooltip: Story = {
111
+ args: {
112
+ ariaLabel: 'Copier le numéro de patient',
113
+ textToCopy: '1970756541',
114
+ hideTooltip: true,
115
+ tooltipDuration: 2000,
116
+ },
117
+ render: (args) => {
118
+ return {
119
+ components: { CopyBtn },
120
+ setup() {
121
+ return { args }
122
+ },
123
+ template: `
124
+ <div class="d-flex flex-wrap align-center pa-4">
125
+ <p class="mb-0 mr-1">
126
+ Patient n°<b>1970756541</b>
127
+ </p>
128
+
129
+ <CopyBtn
130
+ label="Copier le numéro de patient"
131
+ text-to-copy="1970756541"
132
+ :hide-tooltip="args.hideTooltip"
133
+
134
+ />
135
+ </div>
136
+ `,
137
+ }
138
+ },
139
+ }
140
+
141
+ export const SlotIcon: Story = {
142
+ args: {
143
+ ariaLabel: 'Copier le numéro de patient',
144
+ textToCopy: '1970756541',
145
+ hideTooltip: false,
146
+ tooltipDuration: 2000,
147
+ icon: duplicateIcon,
148
+ },
149
+ render: (args) => {
150
+ return {
151
+ components: { CopyBtn, VIcon },
152
+ setup() {
153
+ return { args }
154
+ },
155
+ template: `
156
+ <div class="d-flex flex-wrap align-center pa-4">
157
+ <p class="mb-0 mr-1">
158
+ Patient n°<b>1970756541</b>
159
+ </p>
160
+
161
+ <CopyBtn
162
+ label="Copier le numéro de patient"
163
+ text-to-copy="1970756541"
164
+ :hide-tooltip="args.hideTooltip"
165
+ >
166
+ <template #icon>
167
+ <VIcon :icon="args.icon" />
168
+ </template>
169
+ </CopyBtn>
170
+ </div>
171
+ `,
172
+ }
173
+ },
174
+ }
175
+
176
+ export const SlotTooltip: Story = {
177
+ args: {
178
+ ariaLabel: 'Copier le numéro de patient',
179
+ textToCopy: '1970756541',
180
+ hideTooltip: false,
181
+ tooltipDuration: 2000,
182
+ tooltip: 'Texte personalisé',
183
+ },
184
+ render: (args) => {
185
+ return {
186
+ components: { CopyBtn },
187
+ setup() {
188
+ return { args }
189
+ },
190
+ template: `
191
+ <div class="d-flex flex-wrap align-center pa-4">
192
+ <p class="mb-0 mr-1">
193
+ Patient n°<b>1970756541</b>
194
+ </p>
195
+
196
+ <CopyBtn
197
+ label="Copier le numéro de patient"
198
+ text-to-copy="1970756541"
199
+ :hide-tooltip="args.hideTooltip"
200
+ >
201
+ <template #tooltip>
202
+ {{ args.tooltip }}
203
+ </template>
204
+ </CopyBtn>
205
+ </div>
206
+ `,
207
+ }
208
+ },
209
+ }
@@ -0,0 +1,103 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+ import { VMenu, VIcon, VBtn } from 'vuetify/components'
4
+ import { mdiContentCopy } from '@mdi/js'
5
+
6
+ import useCustomizableOptions, { type CustomizableOptions } from '@/composables/useCustomizableOptions'
7
+ import { copyToClipboard } from '@/utils/functions/copyToClipboard'
8
+
9
+ import { locales } from './locales'
10
+ import { config } from './config'
11
+
12
+ const props = withDefaults(defineProps<CustomizableOptions & {
13
+ ariaLabel?: string
14
+ ariaOwns?: string
15
+ textToCopy: (() => string) | string
16
+ hideTooltip?: boolean
17
+ tooltipDuration?: number
18
+ }>(), {
19
+ ariaLabel: 'copy-btn',
20
+ ariaOwns: 'copy-btn',
21
+ textToCopy: '',
22
+ hideTooltip: false,
23
+ tooltipDuration: 2500,
24
+ })
25
+
26
+ const options = useCustomizableOptions(config, props)
27
+
28
+ const tooltip = ref(false)
29
+ const copyIcon = mdiContentCopy
30
+
31
+ function copy(): void {
32
+ const contentToCopy
33
+ = typeof props.textToCopy === 'function'
34
+ ? props.textToCopy()
35
+ : props.textToCopy
36
+
37
+ copyToClipboard(contentToCopy)
38
+
39
+ if (props.hideTooltip) {
40
+ return
41
+ }
42
+
43
+ setTimeout(() => {
44
+ tooltip.value = false
45
+ }, props.tooltipDuration)
46
+ }
47
+
48
+ defineExpose({
49
+ copy,
50
+ tooltip,
51
+ })
52
+ </script>
53
+
54
+ <template>
55
+ <div
56
+ :id="props.ariaOwns"
57
+ class="vd-copy-btn"
58
+ >
59
+ <VMenu
60
+ v-bind="options.menu"
61
+ :id="props.ariaOwns"
62
+ v-model="tooltip"
63
+ :disabled="props.hideTooltip"
64
+ transition="fade-transition"
65
+ >
66
+ <template #activator="{ props: menuProps }">
67
+ <VBtn
68
+ v-bind="{ ...menuProps, ...options.btn }"
69
+ :aria-label="props.ariaLabel"
70
+ :aria-owns="props.ariaOwns"
71
+ :data-test-id="props.ariaOwns"
72
+ @click="copy"
73
+ >
74
+ <slot name="icon">
75
+ <VIcon v-bind="options.icon">
76
+ {{ copyIcon }}
77
+ </VIcon>
78
+ </slot>
79
+ </VBtn>
80
+ </template>
81
+
82
+ <slot name="tooltip">
83
+ {{ locales.tooltip }}
84
+ </slot>
85
+ </VMenu>
86
+ </div>
87
+ </template>
88
+
89
+ <style lang="scss">
90
+ @use '@/assets/tokens.scss';
91
+
92
+ .vd-copy-tooltip-menu {
93
+ padding: 6px 16px;
94
+ box-shadow: none;
95
+ margin-top: 2px;
96
+ background: rgba(97, 97, 97, 0.9);
97
+ color: white;
98
+ }
99
+
100
+ .v-btn--icon .v-icon {
101
+ color: tokens.$grey-lighten-20;
102
+ }
103
+ </style>
@@ -0,0 +1,17 @@
1
+ import type { VariantType, DensityType, locationType } from '@/types/vuetifyTypes'
2
+ export const config = {
3
+ menu: {
4
+ location: 'end center' as locationType,
5
+ offset: 16,
6
+ zIndex: 8,
7
+ contentClass: 'vd-copy-tooltip-menu text-white text-body-2 ml-2',
8
+ },
9
+ btn: {
10
+ icon: true,
11
+ variant: 'text' as VariantType,
12
+ density: 'comfortable' as DensityType,
13
+ },
14
+ icon: {
15
+ color: 'grey-darken-20',
16
+ },
17
+ }
@@ -0,0 +1,3 @@
1
+ export const locales = {
2
+ tooltip: 'Texte copié !',
3
+ }
@@ -0,0 +1,99 @@
1
+ import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'
2
+ import { mount, shallowMount } from '@vue/test-utils'
3
+ import { vuetify } from '@tests/unit/setup'
4
+
5
+ import CopyBtn from '../CopyBtn.vue'
6
+
7
+ describe('CopyBtn', () => {
8
+ const copy = vi.fn()
9
+
10
+ beforeEach(() => {
11
+ const navigator = {
12
+ clipboard: {
13
+ writeText: copy,
14
+ },
15
+ } as unknown as Navigator
16
+
17
+ vi.spyOn(window, 'navigator', 'get').mockReturnValue(navigator)
18
+
19
+ vi.useFakeTimers()
20
+ })
21
+
22
+ afterEach(() => {
23
+ vi.restoreAllMocks()
24
+ })
25
+
26
+ it('renders correctly', () => {
27
+ const wrapper = shallowMount(CopyBtn, {
28
+ propsData: {
29
+ label: 'test',
30
+ textToCopy: 'test',
31
+ },
32
+ global: {
33
+ plugins: [vuetify],
34
+ },
35
+ })
36
+
37
+ expect(wrapper.html()).toMatchSnapshot()
38
+ })
39
+
40
+ it('copies the text to the clipboard', async () => {
41
+ const wrapper = mount(CopyBtn, {
42
+ propsData: {
43
+ label: 'test',
44
+ textToCopy: 'test',
45
+ },
46
+ global: {
47
+ plugins: [vuetify],
48
+ },
49
+ })
50
+
51
+ await wrapper.find('[data-test-id="copy-btn"]').trigger('click')
52
+
53
+ expect(copy).toHaveBeenCalledWith('test')
54
+
55
+ await wrapper.setProps({
56
+ textToCopy: () => 'function test',
57
+ })
58
+
59
+ await wrapper.find('[data-test-id="copy-btn"]').trigger('click')
60
+
61
+ expect(copy).toHaveBeenCalledWith('function test')
62
+ })
63
+
64
+ it('shows a tooltip when the text is copied', async () => {
65
+ const wrapper = mount(CopyBtn, {
66
+ propsData: {
67
+ label: 'test',
68
+ textToCopy: 'test',
69
+ },
70
+ global: {
71
+ plugins: [vuetify],
72
+ },
73
+ })
74
+
75
+ await wrapper.find('[data-test-id="copy-btn"]').trigger('click')
76
+
77
+ expect(wrapper.vm.tooltip).toBeTruthy()
78
+
79
+ vi.runAllTimers()
80
+ expect(wrapper.vm.tooltip).toBeFalsy()
81
+ })
82
+
83
+ it('does not show a tooltip when the text is copied but hide-tooltip is true', async () => {
84
+ const wrapper = mount(CopyBtn, {
85
+ propsData: {
86
+ label: 'test',
87
+ textToCopy: 'test',
88
+ hideTooltip: true,
89
+ },
90
+ global: {
91
+ plugins: [vuetify],
92
+ },
93
+ })
94
+
95
+ await wrapper.find('[data-test-id="copy-btn"]').trigger('click')
96
+
97
+ expect(wrapper.vm.tooltip).toBeFalsy()
98
+ })
99
+ })
@@ -0,0 +1,7 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`CopyBtn > renders correctly 1`] = `
4
+ "<div id="copy-btn" class="vd-copy-btn" label="test">
5
+ <v-menu-stub offset="16" contentclass="vd-copy-tooltip-menu text-white text-body-2 ml-2" id="copy-btn" submenu="false" attach="false" closeonback="true" contained="false" disabled="false" noclickanimation="false" modelvalue="false" persistent="false" scrim="false" zindex="8" activatorprops="[object Object]" openonhover="false" closeoncontentclick="true" closedelay="250" opendelay="300" eager="false" locationstrategy="connected" location="end center" origin="auto" scrollstrategy="reposition" transition="fade-transition"></v-menu-stub>
6
+ </div>"
7
+ `;
@@ -0,0 +1,5 @@
1
+ import { Meta } from '@storybook/addon-docs';
2
+
3
+ <Meta title="Components/Deprecated" />
4
+
5
+ Folder with Deprecated components
@@ -0,0 +1,94 @@
1
+ import {Controls, Canvas, Meta, Source} from '@storybook/blocks';
2
+
3
+ import * as DownloadBtnStories from './DownloadBtn.stories';
4
+
5
+ <Meta of={DownloadBtnStories} />
6
+
7
+
8
+ # DownloadBtn
9
+
10
+ L'élément `DownloadBtn` est utilisé pour permettre à l'utilisateur de télécharger un document provenant d'une API.
11
+
12
+ <Canvas of={DownloadBtnStories.Default} />
13
+
14
+ # API
15
+
16
+ <Controls of={DownloadBtnStories.Default} />
17
+
18
+ # Exemple d'utilisation
19
+
20
+ <Source dark code={`
21
+ <script setup lang="ts">
22
+ import DownloadBtn from '@/components/DownloadBtn/DownloadBtn.vue'
23
+ import axios from 'axios'
24
+
25
+ function download() {
26
+ return axios.get('https://run.mocky.io/v3/63e571d5-1134-4f51-82ac-fa7cc8045124')
27
+ }
28
+ </script>
29
+
30
+ <template>
31
+ <div>
32
+ <DownloadBtn
33
+ :file-promise="download"
34
+ :btn="{ color: 'primary'}"
35
+ @error="console.error"
36
+ @success="console.info"
37
+ >
38
+ Download
39
+ </DownloadBtn>
40
+ </div>
41
+ </template>
42
+ `} />
43
+
44
+ # Notifier l'utilisateur
45
+
46
+ Vous pouvez utiliser les événements `success` et `error` pour notifier l'utilisateur du succès ou de l'échec du téléchargement.
47
+ Ici avec le composant `NotificationBar` du design system.
48
+
49
+ <Canvas of={DownloadBtnStories.Notify} sourceState="none"/>
50
+
51
+ Exemple :
52
+
53
+ <Source dark code={`
54
+ <script setup lang="ts">
55
+ import DownloadBtn from '@/components/DownloadBtn/DownloadBtn.vue'
56
+ import NotificationBar from '@/components/NotificationBar/NotificationBar.vue'
57
+ import axios from 'axios'
58
+ import { useNotificationService } from '@/services/NotificationService'
59
+ import type { Notification } from '@/components/NotificationBar/types'
60
+
61
+ function download() {
62
+ return axios.get('https://run.mocky.io/v3/63e571d5-1134-4f51-82ac-fa7cc8045124')
63
+ }
64
+
65
+ const { addNotification } = useNotificationService()
66
+
67
+ const notify = (message: string, type: Notification['type']) => {
68
+ const notification: Notification = {
69
+ id: Date.now().toString(),
70
+ message,
71
+ type,
72
+ timeout: -1,
73
+ }
74
+ addNotification(notification)
75
+ }
76
+
77
+ </script>
78
+
79
+ <template>
80
+ <VApp>
81
+ <NotificationBar />
82
+ <div class="d-flex">
83
+ <DownloadBtn
84
+ :file-promise="download"
85
+ :btn="{ color: 'primary'}"
86
+ @error="console.error"
87
+ @success="notify('Votre attestation a été téléchargée', 'success')"
88
+ >
89
+ Download
90
+ </DownloadBtn>
91
+ </div>
92
+ </VApp>
93
+ </template>
94
+ `} />