Skip to content

Commit

Permalink
feat: ✨ exporte les symboles pour les clés d’injection
Browse files Browse the repository at this point in the history
  • Loading branch information
laruiss committed Sep 12, 2024
1 parent bbc4458 commit d65cc77
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions ci/check-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const isCI = process.argv.includes('--ci')
const getNormalizedDir = (relativeDir) => fileURLToPath(new URL(relativeDir, import.meta.url))

// const sfcs = await globby(fileURLToPath(new URL('../src/components/**/*.vue', import.meta.url)))
const sfcs = (await globby('src/components/**/*.{vue,types.ts}'))
.filter(path => !/Demo|Example/.test(path))
const sfcs = (await globby('src/components/**/*.{vue,ts}'))
.filter(path => !/Demo|Example|stories|spec\.ts|index\.ts/.test(path))
.map(path => path.replace(/^(.*).types.ts$/, '$1.types'))

const projectFn = component => component.endsWith('types')
? `export * from '${component.replace('src/components', '.')}'`
const projectFn = component => (component.endsWith('types') || component.includes('injection-key.ts'))
? `export * from '${component.replace('src/components', '.').replace(/\.ts$/, '')}'`
: `export { default as ${path.basename(component, '.vue')} } from '${component.replace('src/components', '.')}'`

const correctComponentList = sfcs.map(projectFn).sort()
Expand Down
1 change: 1 addition & 0 deletions src/components/DsfrAccordion/DsfrAccordion.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ Ce composant peut être utilisé uniquement avec [`DsfrAccordionsGroup`](/compos
::: code-group
<<< DsfrAccordion.vue
<<< DsfrAccordion.types.ts
<<< injection-key.ts
:::
4 changes: 2 additions & 2 deletions src/components/DsfrAccordion/DsfrAccordion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { inject, onMounted, ref, toRef, watch } from 'vue'
import { useCollapsable } from '../../composables'
import { getRandomId } from '../../utils/random-utils'
import { registerTabKey } from './injection-key'
import { registerAccordionKey } from './injection-key'
import type { DsfrAccordionProps } from './DsfrAccordion.types'
export type { DsfrAccordionProps }
Expand All @@ -27,7 +27,7 @@ const {
const isStandaloneActive = ref()
const useAccordion = inject(registerTabKey)!
const useAccordion = inject(registerAccordionKey)!
const { isActive, expand } = useAccordion?.(toRef(() => props.title)) ?? { isActive: isStandaloneActive, expand: () => isStandaloneActive.value = !isStandaloneActive.value }
onMounted(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DsfrAccordion/injection-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ type RegisterTab = (title: Ref<string>) => {
expand: () => void
}

export const registerTabKey: InjectionKey<RegisterTab> = Symbol('accordions')
export const registerAccordionKey: InjectionKey<RegisterTab> = Symbol('accordions')
1 change: 1 addition & 0 deletions src/components/DsfrHeader/DsfrHeader.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Exemple plus complet sur l’[application de demo](https://demo.vue-ds.fr/) (don

<<< DsfrHeader.vue
<<< DsfrHeader.types.ts
<<< injection-key.ts

:::

Expand Down
1 change: 1 addition & 0 deletions src/components/DsfrTabs/DsfrTabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ activeTab.value = tabTitles.length - 1 // active le dernier onglet
<<< DsfrTabContent.vue
<<< DsfrTabItem.vue
<<< DsfrTabs.types.ts
<<< injection-key.ts
:::

<script setup lang="ts">
Expand Down
3 changes: 3 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './DsfrAccordion/DsfrAccordion.types'
export * from './DsfrAccordion/injection-key'
export * from './DsfrAlert/DsfrAlert.types'
export * from './DsfrBackToTop/DsfrBackToTop.types'
export * from './DsfrBadge/DsfrBadge.types'
Expand All @@ -17,6 +18,7 @@ export * from './DsfrFollow/DsfrFollow.types'
export * from './DsfrFooter/DsfrFooter.types'
export * from './DsfrFranceConnect/DsfrFranceConnect.types'
export * from './DsfrHeader/DsfrHeader.types'
export * from './DsfrHeader/injection-key'
export * from './DsfrHighlight/DsfrHighlight.types'
export * from './DsfrInput/DsfrInput.types'
export * from './DsfrLanguageSelector/DsfrLanguageSelector.types'
Expand All @@ -39,6 +41,7 @@ export * from './DsfrStepper/DsfrStepper.types'
export * from './DsfrSummary/DsfrSummary.types'
export * from './DsfrTable/DsfrTable.types'
export * from './DsfrTabs/DsfrTabs.types'
export * from './DsfrTabs/injection-key'
export * from './DsfrTag/DsfrTags.types'
export * from './DsfrTile/DsfrTiles.types'
export * from './DsfrToggleSwitch/DsfrToggleSwitch.types'
Expand Down

0 comments on commit d65cc77

Please sign in to comment.