fds-vue-core 9.0.0 → 9.2.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.
- package/components.d.ts +4 -0
- package/dist/components/Buttons/FdsButtonIcon/FdsButtonIcon.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/components/Buttons/FdsButtonIcon/FdsButtonIcon.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/Buttons/FdsButtonIcon/types.d.ts +1 -0
- package/dist/components/FdsSearchSelectPro/FdsSearchSelectPro.js.map +1 -1
- package/dist/components/FdsSearchSelectPro/FdsSearchSelectPro.vue.d.ts +1 -0
- package/dist/components/FdsSearchSelectPro/FdsSearchSelectPro.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/components/FdsSearchSelectPro/FdsSearchSelectPro.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/FdsSearchSelectPro/types.d.ts +2 -0
- package/dist/components/FdsSearchSelectPro/useSearchSelectProItems.js +1 -1
- package/dist/components/FdsSearchSelectPro/useSearchSelectProItems.js.map +1 -1
- package/dist/components/FdsSnackbar/FdsSnackbar.js +6 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.js.map +1 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.vue.d.ts +7 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.vue_vue_type_script_setup_true_lang.js +78 -0
- package/dist/components/FdsSnackbar/FdsSnackbar.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsSnackbar/types.d.ts +16 -0
- package/dist/components/FdsSnackbar/useSnackbar.d.ts +40 -0
- package/dist/components/FdsSnackbar/useSnackbar.js +19 -0
- package/dist/components/FdsSnackbar/useSnackbar.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.js +6 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.vue.d.ts +8 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.vue_vue_type_script_setup_true_lang.js +58 -0
- package/dist/components/FdsToastMessage/FdsToastMessage.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.js +6 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.vue.d.ts +20 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.vue_vue_type_script_setup_true_lang.js +185 -0
- package/dist/components/FdsToastMessage/FdsToastMessageCard.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.js +8 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.js.map +1 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.vue.d.ts +28 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.vue_vue_type_script_setup_true_lang.js +81 -0
- package/dist/components/FdsToastMessage/FdsToastRegions.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/FdsToastMessage/createMessageQueue.d.ts +19 -0
- package/dist/components/FdsToastMessage/createMessageQueue.js +50 -0
- package/dist/components/FdsToastMessage/createMessageQueue.js.map +1 -0
- package/dist/components/FdsToastMessage/getReadingDuration.d.ts +1 -0
- package/dist/components/FdsToastMessage/getReadingDuration.js +11 -0
- package/dist/components/FdsToastMessage/getReadingDuration.js.map +1 -0
- package/dist/components/FdsToastMessage/types.d.ts +20 -0
- package/dist/components/FdsToastMessage/useToastMessage.d.ts +40 -0
- package/dist/components/FdsToastMessage/useToastMessage.js +19 -0
- package/dist/components/FdsToastMessage/useToastMessage.js.map +1 -0
- package/dist/fds-vue-core.css +2 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/lang/en.js +6 -0
- package/dist/lang/en.js.map +1 -1
- package/dist/lang/sv.js +6 -0
- package/dist/lang/sv.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/src/components/Buttons/FdsButtonIcon/types.ts +1 -0
- package/src/components/FdsSearchSelectPro/FdsSearchSelectPro.stories.ts +24 -0
- package/src/components/FdsSearchSelectPro/FdsSearchSelectPro.vue +1 -0
- package/src/components/FdsSearchSelectPro/types.ts +2 -0
- package/src/components/FdsSearchSelectPro/useSearchSelectProItems.ts +1 -1
- package/src/components/FdsSnackbar/FdsSnackbar.stories.ts +111 -0
- package/src/components/FdsSnackbar/FdsSnackbar.vue +74 -0
- package/src/components/FdsSnackbar/types.ts +21 -0
- package/src/components/FdsSnackbar/useSnackbar.ts +19 -0
- package/src/components/FdsToastMessage/FdsToastMessage.stories.ts +122 -0
- package/src/components/FdsToastMessage/FdsToastMessage.vue +44 -0
- package/src/components/FdsToastMessage/FdsToastMessageCard.vue +173 -0
- package/src/components/FdsToastMessage/FdsToastRegions.vue +114 -0
- package/src/components/FdsToastMessage/createMessageQueue.ts +57 -0
- package/src/components/FdsToastMessage/getReadingDuration.ts +8 -0
- package/src/components/FdsToastMessage/types.ts +31 -0
- package/src/components/FdsToastMessage/useToastMessage.ts +19 -0
- package/src/index.ts +27 -0
- package/src/lang/en.json +6 -0
- package/src/lang/sv.json +6 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearchSelectProItems.js","names":[],"sources":["../../../src/components/FdsSearchSelectPro/useSearchSelectProItems.ts"],"sourcesContent":["import { computed, ref, type ComputedRef, type Ref } from 'vue'\nimport { normalizePidSearchValue } from '../../composables/useIsPid'\nimport { useFdsI18n } from '../../plugin/useFdsI18n'\nimport type { FdsSearchSelectProProps } from './types'\n\ntype SearchSelectItem = Record<string, unknown>\n\nexport const useSearchSelectProItems = ({\n props,\n searchFields,\n searchTerm,\n bypassSearchFilter,\n showSelectedOnly,\n selectedItems,\n isMultiple,\n isPid,\n}: {\n props: FdsSearchSelectProProps\n searchFields: ComputedRef<string[]>\n searchTerm: Ref<string>\n bypassSearchFilter: Ref<boolean>\n showSelectedOnly: Ref<boolean>\n selectedItems: Ref<SearchSelectItem[]>\n isMultiple: ComputedRef<boolean>\n isPid: Ref<boolean>\n}) => {\n const { locale: activeLocale, t } = useFdsI18n()\n const matchingItems = ref<SearchSelectItem[]>([])\n const displayedItems = ref<SearchSelectItem[]>([])\n const visibleItemsLimit = ref<number | null>(props.maxItems && props.maxItems > 0 ? props.maxItems : null)\n const resolvedLocale = computed<'en' | 'sv'>(() => (activeLocale.value.toLowerCase().startsWith('en') ? 'en' : 'sv'))\n\n const toStableValue = (value: unknown): unknown => {\n if (Array.isArray(value)) {\n return value.map((item) => toStableValue(item))\n }\n\n if (value && typeof value === 'object') {\n const sortedObject: Record<string, unknown> = {}\n Object.keys(value as Record<string, unknown>)\n .sort()\n .forEach((key) => {\n sortedObject[key] = toStableValue((value as Record<string, unknown>)[key])\n })\n return sortedObject\n }\n\n return value\n }\n\n const getItemIdentifier = (item: SearchSelectItem): string => {\n const { itemKey } = props\n if (itemKey && item[itemKey] !== undefined) {\n return String(item[itemKey])\n }\n return JSON.stringify(toStableValue(item))\n }\n\n const isDividerItem = (item: SearchSelectItem): boolean => {\n const dividerField = props.dividerField ?? 'isDivider'\n const dividerValue = item[dividerField]\n return dividerValue === true || item.type === 'divider'\n }\n\n const isItemSelected = (item: SearchSelectItem): boolean => {\n const itemId = getItemIdentifier(item)\n return selectedItems.value.some((selected) => getItemIdentifier(selected) === itemId)\n }\n\n const isHierarchyPaddingEnabled = computed(\n () => isMultiple.value && props.hierarchical && !searchTerm.value.length && !showSelectedOnly.value,\n )\n\n const hasDividerMode = computed(\n () =>\n !!props.autoDividerBy ||\n (props.items ?? []).some((item) => {\n const dividerField = props.dividerField ?? 'isDivider'\n const dividerValue = item[dividerField]\n return dividerValue === true || item.type === 'divider'\n }),\n )\n\n const isDividerPaddingEnabled = computed(\n () => hasDividerMode.value && !props.hierarchical && !searchTerm.value.length && !showSelectedOnly.value,\n )\n\n const optionPaddingStyle = (item: SearchSelectItem) => {\n if (isDividerItem(item)) return null\n\n if (isHierarchyPaddingEnabled.value) {\n const levelField = props.levelField ?? 'level'\n const level = Number(item[levelField] ?? 0)\n const safeLevel = Number.isFinite(level) && level > 0 ? level : 0\n return {\n paddingLeft: `${12 + safeLevel * 12}px`,\n }\n }\n\n if (isDividerPaddingEnabled.value) {\n return {\n paddingLeft: '24px',\n }\n }\n\n return null\n }\n\n const getItemSortValue = (item: SearchSelectItem): string => {\n const primaryField = searchFields.value[0]\n if (primaryField && item[primaryField] !== undefined && item[primaryField] !== null) {\n return String(item[primaryField])\n }\n if (item.label !== undefined && item.label !== null) {\n return String(item.label)\n }\n if (item.name !== undefined && item.name !== null) {\n return String(item.name)\n }\n return ''\n }\n\n const reorderExplicitDividerGroups = (items: SearchSelectItem[], locale: 'en' | 'sv'): SearchSelectItem[] => {\n const dividerLabelField = searchFields.value[0] ?? 'label'\n const unspecifiedGroupKey = '__UNSPECIFIED__'\n const defaultUnspecifiedLabel = t('FdsSearchSelectPro.unspecified')\n const unspecifiedLabel = String(props.unspecifiedLabel ?? '').trim() || defaultUnspecifiedLabel\n\n const isUnspecifiedDividerLabel = (raw: string): boolean => {\n const trimmed = raw.trim()\n if (!trimmed) return true\n const lower = trimmed.toLowerCase()\n if (lower === unspecifiedGroupKey.toLowerCase()) return true\n const candidates = new Set(\n [unspecifiedLabel, defaultUnspecifiedLabel]\n .map((s) => s.trim().toLowerCase())\n .filter(Boolean),\n )\n return candidates.has(lower)\n }\n\n const groups: Array<{\n divider: SearchSelectItem | null\n children: SearchSelectItem[]\n label: string\n unspecified: boolean\n }> = []\n let current = {\n divider: null as SearchSelectItem | null,\n children: [] as SearchSelectItem[],\n label: '',\n unspecified: false,\n }\n\n const flush = () => {\n if (current.divider || current.children.length) groups.push(current)\n }\n\n items.forEach((item) => {\n if (isDividerItem(item)) {\n flush()\n const raw = String(item[dividerLabelField] ?? item.label ?? item.name ?? '').trim()\n const isUnspecified = isUnspecifiedDividerLabel(raw)\n current = {\n divider: item,\n children: [],\n label: isUnspecified ? unspecifiedLabel : raw,\n unspecified: isUnspecified,\n }\n } else {\n current.children.push(item)\n }\n })\n flush()\n\n const [prefix, ...rest] = groups\n rest.sort((a, b) => {\n if (a.unspecified && !b.unspecified) return 1\n if (b.unspecified && !a.unspecified) return -1\n return a.label.localeCompare(b.label, locale)\n })\n\n const ordered = prefix ? [prefix, ...rest] : rest\n return ordered.flatMap((g) => (g.divider ? [g.divider, ...g.children] : [...g.children]))\n }\n\n const sourceItems = computed(() => {\n const baseItems = props.items ?? []\n const groupField = props.autoDividerBy\n if (!groupField) {\n const dividerField = props.dividerField ?? 'isDivider'\n const hasExplicitDividers = baseItems.some((item) => item[dividerField] === true || item.type === 'divider')\n if (!hasExplicitDividers) return baseItems\n\n const locale = resolvedLocale.value\n return reorderExplicitDividerGroups(baseItems, locale)\n }\n const dividerField = props.dividerField ?? 'isDivider'\n const levelField = props.levelField ?? 'level'\n\n const locale = resolvedLocale.value\n const defaultUnspecifiedLabel = t('FdsSearchSelectPro.unspecified')\n const unspecifiedLabel = String(props.unspecifiedLabel ?? '').trim() || defaultUnspecifiedLabel\n const grouped = new Map<string, SearchSelectItem[]>()\n const groupLabels = new Map<string, string>()\n const unspecifiedGroupKey = '__UNSPECIFIED__'\n\n baseItems.forEach((item) => {\n const groupValue = String(item[groupField] ?? '').trim()\n const groupKey = groupValue || unspecifiedGroupKey\n const groupLabel = groupValue || unspecifiedLabel\n\n if (!grouped.has(groupKey)) {\n grouped.set(groupKey, [])\n groupLabels.set(groupKey, groupLabel)\n }\n grouped.get(groupKey)?.push(item)\n })\n\n const sortedGroups = [...grouped.keys()].sort((a, b) => {\n if (a === unspecifiedGroupKey) return 1\n if (b === unspecifiedGroupKey) return -1\n return (groupLabels.get(a) ?? a).localeCompare(groupLabels.get(b) ?? b, locale)\n })\n const flattened: SearchSelectItem[] = []\n const dividerLabelField = searchFields.value[0] ?? 'label'\n\n sortedGroups.forEach((groupKey) => {\n const groupItems = grouped.get(groupKey) ?? []\n const groupLabel = groupLabels.get(groupKey) ?? groupKey\n const dividerItem: SearchSelectItem = {\n type: 'divider',\n [dividerField]: true,\n [levelField]: 0,\n [groupField]: groupLabel,\n [dividerLabelField]: groupLabel,\n label: groupLabel,\n }\n flattened.push(dividerItem)\n\n const sortedItems = [...groupItems].sort((a, b) => getItemSortValue(a).localeCompare(getItemSortValue(b), locale))\n flattened.push(...sortedItems)\n })\n\n return flattened\n })\n\n const sortResponse = (response: SearchSelectItem[]) => {\n if (!response.length) return []\n const firstItem = response[0] ?? {}\n const allKeys = [...searchFields.value, ...Object.keys(firstItem).filter((k) => !searchFields.value.includes(k))]\n return response.map((item) => {\n const sorted: Record<string, unknown> = {}\n allKeys.forEach((key) => {\n sorted[key] = item[key] || `${key}: den här uppgiften saknas.`\n })\n return sorted\n })\n }\n\n const matchesSearchTerm = (item: SearchSelectItem): boolean => {\n if (bypassSearchFilter.value) return true\n if (!searchTerm.value) return true\n\n const searchValue = isPid.value ? normalizePidSearchValue(searchTerm.value) : searchTerm.value\n const searchLower = searchValue.toLowerCase()\n const pidRegex = /^\\d{8}[a-zA-Z0-9]{4}$/\n if (pidRegex.test(searchValue)) return true\n\n return searchFields.value.some((key) => {\n const value = item[key]\n if (!value) return false\n\n const stringValue = String(value)\n const valueLower = stringValue.toLowerCase()\n const unmaskedValue = isPid.value\n ? normalizePidSearchValue(stringValue)\n : stringValue.replace(/\\D/g, '')\n return (\n valueLower.includes(searchLower) ||\n (unmaskedValue.length > 0 && unmaskedValue.toLowerCase().includes(searchLower))\n )\n })\n }\n\n const matchesDividerSearchTerm = (item: SearchSelectItem): boolean => {\n if (bypassSearchFilter.value) return false\n if (!isDividerItem(item) || !searchTerm.value) return false\n\n const searchValue = isPid.value ? normalizePidSearchValue(searchTerm.value) : searchTerm.value\n const searchLower = searchValue.toLowerCase()\n const dividerSearchFields = [...searchFields.value, 'label', 'name']\n\n return dividerSearchFields.some((field) => {\n const value = item[field]\n if (!value) return false\n return String(value).toLowerCase().includes(searchLower)\n })\n }\n\n const filterWithDividerGroups = (sourceData: SearchSelectItem[]): SearchSelectItem[] => {\n if (bypassSearchFilter.value || !searchTerm.value) return sourceData\n\n const matched: SearchSelectItem[] = []\n let currentDivider: SearchSelectItem | null = null\n let currentChildren: SearchSelectItem[] = []\n\n const flushCurrentGroup = () => {\n if (!currentDivider) {\n matched.push(...currentChildren.filter((item) => matchesSearchTerm(item)))\n } else {\n const dividerMatched = matchesDividerSearchTerm(currentDivider)\n const matchedChildren = currentChildren.filter((item) => matchesSearchTerm(item))\n\n if (!dividerMatched && matchedChildren.length === 0) {\n return\n }\n\n if (dividerMatched || props.showOutOfBoundsDivider !== false) {\n matched.push(currentDivider)\n }\n if (dividerMatched) {\n matched.push(...currentChildren)\n } else {\n matched.push(...matchedChildren)\n }\n }\n }\n\n sourceData.forEach((item) => {\n if (isDividerItem(item)) {\n flushCurrentGroup()\n currentDivider = item\n currentChildren = []\n return\n }\n\n currentChildren.push(item)\n })\n\n flushCurrentGroup()\n\n return matched\n }\n\n const filterAndPaginate = (onTotal: (count: number) => void) => {\n if (!sourceItems.value.length) {\n matchingItems.value = []\n displayedItems.value = []\n onTotal(0)\n return\n }\n\n let sourceData = sourceItems.value\n if (props.preserveOrder && sourceData.length) {\n sourceData = sortResponse(sourceData)\n }\n\n const matchedArray = hasDividerMode.value\n ? filterWithDividerGroups(sourceData)\n : sourceData.filter((item) => matchesSearchTerm(item))\n matchingItems.value = matchedArray\n\n const shouldLimitItems = props.maxItems !== undefined && props.maxItems > 0\n const effectiveLimit = shouldLimitItems ? (visibleItemsLimit.value ?? props.maxItems) : null\n\n if (isMultiple.value && showSelectedOnly.value) {\n const selectedOnlyItems = matchedArray.filter((item) => isItemSelected(item))\n displayedItems.value = effectiveLimit !== null ? selectedOnlyItems.slice(0, effectiveLimit) : selectedOnlyItems\n } else {\n displayedItems.value = effectiveLimit !== null ? matchedArray.slice(0, effectiveLimit) : matchedArray\n }\n\n const totalMatchingCount = matchingItems.value.filter(\n (item) => props.dividerSelectable || !isDividerItem(item),\n ).length\n onTotal(totalMatchingCount)\n }\n\n const resetVisibleItemsLimit = () => {\n visibleItemsLimit.value = props.maxItems && props.maxItems > 0 ? props.maxItems : null\n }\n\n const syncSelectedItemsWithItems = () => {\n const currentItems = props.items ?? []\n const currentIds = new Set(currentItems.map((item) => getItemIdentifier(item)))\n selectedItems.value = selectedItems.value.filter((item) => currentIds.has(getItemIdentifier(item)))\n }\n\n const hasInternalMoreItems = computed(() => matchingItems.value.length > displayedItems.value.length)\n const hasMoreServerPages = computed(() => {\n if (props.page === undefined || props.totalPages === undefined) return false\n return props.page < props.totalPages\n })\n const shouldShowLoadMore = computed(() => {\n if (isMultiple.value && showSelectedOnly.value) return false\n if (hasInternalMoreItems.value) return true\n if (hasMoreServerPages.value) return true\n if (props.maxItems && props.maxItems > 0) return false\n return props.showLoadMore\n })\n\n const handleInternalLoadMore = (): boolean => {\n if (props.maxItems && props.maxItems > 0 && hasInternalMoreItems.value) {\n visibleItemsLimit.value = (visibleItemsLimit.value ?? props.maxItems) + props.maxItems\n return true\n }\n return false\n }\n\n return {\n displayedItems,\n filterAndPaginate,\n getItemIdentifier,\n isDividerItem,\n isItemSelected,\n optionPaddingStyle,\n sourceItems,\n resetVisibleItemsLimit,\n shouldShowLoadMore,\n handleInternalLoadMore,\n syncSelectedItemsWithItems,\n }\n}\n"],"mappings":";;;;AAOA,IAAa,2BAA2B,EACtC,OACA,cACA,YACA,oBACA,kBACA,eACA,YACA,YAUI;CACJ,MAAM,EAAE,QAAQ,cAAc,MAAM,WAAW;CAC/C,MAAM,gBAAgB,IAAwB,CAAC,CAAC;CAChD,MAAM,iBAAiB,IAAwB,CAAC,CAAC;CACjD,MAAM,oBAAoB,IAAmB,MAAM,YAAY,MAAM,WAAW,IAAI,MAAM,WAAW,IAAI;CACzG,MAAM,iBAAiB,eAA6B,aAAa,MAAM,YAAY,CAAC,CAAC,WAAW,IAAI,IAAI,OAAO,IAAK;CAEpH,MA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M,YAAY,MAAM;GAC9E,OAAO;EACT;EACA,OAAO;CACT;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useSearchSelectProItems.js","names":[],"sources":["../../../src/components/FdsSearchSelectPro/useSearchSelectProItems.ts"],"sourcesContent":["import { computed, ref, type ComputedRef, type Ref } from 'vue'\nimport { normalizePidSearchValue } from '../../composables/useIsPid'\nimport { useFdsI18n } from '../../plugin/useFdsI18n'\nimport type { FdsSearchSelectProProps } from './types'\n\ntype SearchSelectItem = Record<string, unknown>\n\nexport const useSearchSelectProItems = ({\n props,\n searchFields,\n searchTerm,\n bypassSearchFilter,\n showSelectedOnly,\n selectedItems,\n isMultiple,\n isPid,\n}: {\n props: FdsSearchSelectProProps\n searchFields: ComputedRef<string[]>\n searchTerm: Ref<string>\n bypassSearchFilter: Ref<boolean>\n showSelectedOnly: Ref<boolean>\n selectedItems: Ref<SearchSelectItem[]>\n isMultiple: ComputedRef<boolean>\n isPid: Ref<boolean>\n}) => {\n const { locale: activeLocale, t } = useFdsI18n()\n const matchingItems = ref<SearchSelectItem[]>([])\n const displayedItems = ref<SearchSelectItem[]>([])\n const visibleItemsLimit = ref<number | null>(props.maxItems && props.maxItems > 0 ? props.maxItems : null)\n const resolvedLocale = computed<'en' | 'sv'>(() => (activeLocale.value.toLowerCase().startsWith('en') ? 'en' : 'sv'))\n\n const toStableValue = (value: unknown): unknown => {\n if (Array.isArray(value)) {\n return value.map((item) => toStableValue(item))\n }\n\n if (value && typeof value === 'object') {\n const sortedObject: Record<string, unknown> = {}\n Object.keys(value as Record<string, unknown>)\n .sort()\n .forEach((key) => {\n sortedObject[key] = toStableValue((value as Record<string, unknown>)[key])\n })\n return sortedObject\n }\n\n return value\n }\n\n const getItemIdentifier = (item: SearchSelectItem): string => {\n const { itemKey } = props\n if (itemKey && item[itemKey] !== undefined) {\n return String(item[itemKey])\n }\n return JSON.stringify(toStableValue(item))\n }\n\n const isDividerItem = (item: SearchSelectItem): boolean => {\n const dividerField = props.dividerField ?? 'isDivider'\n const dividerValue = item[dividerField]\n return dividerValue === true || item.type === 'divider'\n }\n\n const isItemSelected = (item: SearchSelectItem): boolean => {\n const itemId = getItemIdentifier(item)\n return selectedItems.value.some((selected) => getItemIdentifier(selected) === itemId)\n }\n\n const isHierarchyPaddingEnabled = computed(\n () => isMultiple.value && props.hierarchical && !searchTerm.value.length && !showSelectedOnly.value,\n )\n\n const hasDividerMode = computed(\n () =>\n !!props.autoDividerBy ||\n (props.items ?? []).some((item) => {\n const dividerField = props.dividerField ?? 'isDivider'\n const dividerValue = item[dividerField]\n return dividerValue === true || item.type === 'divider'\n }),\n )\n\n const isDividerPaddingEnabled = computed(\n () => hasDividerMode.value && !props.hierarchical && !searchTerm.value.length && !showSelectedOnly.value,\n )\n\n const optionPaddingStyle = (item: SearchSelectItem) => {\n if (isDividerItem(item)) return null\n\n if (isHierarchyPaddingEnabled.value) {\n const levelField = props.levelField ?? 'level'\n const level = Number(item[levelField] ?? 0)\n const safeLevel = Number.isFinite(level) && level > 0 ? level : 0\n return {\n paddingLeft: `${12 + safeLevel * 12}px`,\n }\n }\n\n if (isDividerPaddingEnabled.value) {\n return {\n paddingLeft: '24px',\n }\n }\n\n return null\n }\n\n const getItemSortValue = (item: SearchSelectItem): string => {\n const primaryField = searchFields.value[0]\n if (primaryField && item[primaryField] !== undefined && item[primaryField] !== null) {\n return String(item[primaryField])\n }\n if (item.label !== undefined && item.label !== null) {\n return String(item.label)\n }\n if (item.name !== undefined && item.name !== null) {\n return String(item.name)\n }\n return ''\n }\n\n const reorderExplicitDividerGroups = (items: SearchSelectItem[], locale: 'en' | 'sv'): SearchSelectItem[] => {\n const dividerLabelField = searchFields.value[0] ?? 'label'\n const unspecifiedGroupKey = '__UNSPECIFIED__'\n const defaultUnspecifiedLabel = t('FdsSearchSelectPro.unspecified')\n const unspecifiedLabel = String(props.unspecifiedLabel ?? '').trim() || defaultUnspecifiedLabel\n\n const isUnspecifiedDividerLabel = (raw: string): boolean => {\n const trimmed = raw.trim()\n if (!trimmed) return true\n const lower = trimmed.toLowerCase()\n if (lower === unspecifiedGroupKey.toLowerCase()) return true\n const candidates = new Set(\n [unspecifiedLabel, defaultUnspecifiedLabel]\n .map((s) => s.trim().toLowerCase())\n .filter(Boolean),\n )\n return candidates.has(lower)\n }\n\n const groups: Array<{\n divider: SearchSelectItem | null\n children: SearchSelectItem[]\n label: string\n unspecified: boolean\n }> = []\n let current = {\n divider: null as SearchSelectItem | null,\n children: [] as SearchSelectItem[],\n label: '',\n unspecified: false,\n }\n\n const flush = () => {\n if (current.divider || current.children.length) groups.push(current)\n }\n\n items.forEach((item) => {\n if (isDividerItem(item)) {\n flush()\n const raw = String(item[dividerLabelField] ?? item.label ?? item.name ?? '').trim()\n const isUnspecified = isUnspecifiedDividerLabel(raw)\n current = {\n divider: item,\n children: [],\n label: isUnspecified ? unspecifiedLabel : raw,\n unspecified: isUnspecified,\n }\n } else {\n current.children.push(item)\n }\n })\n flush()\n\n const [prefix, ...rest] = groups\n rest.sort((a, b) => {\n if (a.unspecified && !b.unspecified) return 1\n if (b.unspecified && !a.unspecified) return -1\n return a.label.localeCompare(b.label, locale)\n })\n\n const ordered = prefix ? [prefix, ...rest] : rest\n return ordered.flatMap((g) => (g.divider ? [g.divider, ...g.children] : [...g.children]))\n }\n\n const sourceItems = computed(() => {\n const baseItems = props.items ?? []\n const groupField = props.autoDividerBy\n if (!groupField) {\n const dividerField = props.dividerField ?? 'isDivider'\n const hasExplicitDividers = baseItems.some((item) => item[dividerField] === true || item.type === 'divider')\n if (!hasExplicitDividers || props.keepDividerOrder) return baseItems\n\n const locale = resolvedLocale.value\n return reorderExplicitDividerGroups(baseItems, locale)\n }\n const dividerField = props.dividerField ?? 'isDivider'\n const levelField = props.levelField ?? 'level'\n\n const locale = resolvedLocale.value\n const defaultUnspecifiedLabel = t('FdsSearchSelectPro.unspecified')\n const unspecifiedLabel = String(props.unspecifiedLabel ?? '').trim() || defaultUnspecifiedLabel\n const grouped = new Map<string, SearchSelectItem[]>()\n const groupLabels = new Map<string, string>()\n const unspecifiedGroupKey = '__UNSPECIFIED__'\n\n baseItems.forEach((item) => {\n const groupValue = String(item[groupField] ?? '').trim()\n const groupKey = groupValue || unspecifiedGroupKey\n const groupLabel = groupValue || unspecifiedLabel\n\n if (!grouped.has(groupKey)) {\n grouped.set(groupKey, [])\n groupLabels.set(groupKey, groupLabel)\n }\n grouped.get(groupKey)?.push(item)\n })\n\n const sortedGroups = [...grouped.keys()].sort((a, b) => {\n if (a === unspecifiedGroupKey) return 1\n if (b === unspecifiedGroupKey) return -1\n return (groupLabels.get(a) ?? a).localeCompare(groupLabels.get(b) ?? b, locale)\n })\n const flattened: SearchSelectItem[] = []\n const dividerLabelField = searchFields.value[0] ?? 'label'\n\n sortedGroups.forEach((groupKey) => {\n const groupItems = grouped.get(groupKey) ?? []\n const groupLabel = groupLabels.get(groupKey) ?? groupKey\n const dividerItem: SearchSelectItem = {\n type: 'divider',\n [dividerField]: true,\n [levelField]: 0,\n [groupField]: groupLabel,\n [dividerLabelField]: groupLabel,\n label: groupLabel,\n }\n flattened.push(dividerItem)\n\n const sortedItems = [...groupItems].sort((a, b) => getItemSortValue(a).localeCompare(getItemSortValue(b), locale))\n flattened.push(...sortedItems)\n })\n\n return flattened\n })\n\n const sortResponse = (response: SearchSelectItem[]) => {\n if (!response.length) return []\n const firstItem = response[0] ?? {}\n const allKeys = [...searchFields.value, ...Object.keys(firstItem).filter((k) => !searchFields.value.includes(k))]\n return response.map((item) => {\n const sorted: Record<string, unknown> = {}\n allKeys.forEach((key) => {\n sorted[key] = item[key] || `${key}: den här uppgiften saknas.`\n })\n return sorted\n })\n }\n\n const matchesSearchTerm = (item: SearchSelectItem): boolean => {\n if (bypassSearchFilter.value) return true\n if (!searchTerm.value) return true\n\n const searchValue = isPid.value ? normalizePidSearchValue(searchTerm.value) : searchTerm.value\n const searchLower = searchValue.toLowerCase()\n const pidRegex = /^\\d{8}[a-zA-Z0-9]{4}$/\n if (pidRegex.test(searchValue)) return true\n\n return searchFields.value.some((key) => {\n const value = item[key]\n if (!value) return false\n\n const stringValue = String(value)\n const valueLower = stringValue.toLowerCase()\n const unmaskedValue = isPid.value\n ? normalizePidSearchValue(stringValue)\n : stringValue.replace(/\\D/g, '')\n return (\n valueLower.includes(searchLower) ||\n (unmaskedValue.length > 0 && unmaskedValue.toLowerCase().includes(searchLower))\n )\n })\n }\n\n const matchesDividerSearchTerm = (item: SearchSelectItem): boolean => {\n if (bypassSearchFilter.value) return false\n if (!isDividerItem(item) || !searchTerm.value) return false\n\n const searchValue = isPid.value ? normalizePidSearchValue(searchTerm.value) : searchTerm.value\n const searchLower = searchValue.toLowerCase()\n const dividerSearchFields = [...searchFields.value, 'label', 'name']\n\n return dividerSearchFields.some((field) => {\n const value = item[field]\n if (!value) return false\n return String(value).toLowerCase().includes(searchLower)\n })\n }\n\n const filterWithDividerGroups = (sourceData: SearchSelectItem[]): SearchSelectItem[] => {\n if (bypassSearchFilter.value || !searchTerm.value) return sourceData\n\n const matched: SearchSelectItem[] = []\n let currentDivider: SearchSelectItem | null = null\n let currentChildren: SearchSelectItem[] = []\n\n const flushCurrentGroup = () => {\n if (!currentDivider) {\n matched.push(...currentChildren.filter((item) => matchesSearchTerm(item)))\n } else {\n const dividerMatched = matchesDividerSearchTerm(currentDivider)\n const matchedChildren = currentChildren.filter((item) => matchesSearchTerm(item))\n\n if (!dividerMatched && matchedChildren.length === 0) {\n return\n }\n\n if (dividerMatched || props.showOutOfBoundsDivider !== false) {\n matched.push(currentDivider)\n }\n if (dividerMatched) {\n matched.push(...currentChildren)\n } else {\n matched.push(...matchedChildren)\n }\n }\n }\n\n sourceData.forEach((item) => {\n if (isDividerItem(item)) {\n flushCurrentGroup()\n currentDivider = item\n currentChildren = []\n return\n }\n\n currentChildren.push(item)\n })\n\n flushCurrentGroup()\n\n return matched\n }\n\n const filterAndPaginate = (onTotal: (count: number) => void) => {\n if (!sourceItems.value.length) {\n matchingItems.value = []\n displayedItems.value = []\n onTotal(0)\n return\n }\n\n let sourceData = sourceItems.value\n if (props.preserveOrder && sourceData.length) {\n sourceData = sortResponse(sourceData)\n }\n\n const matchedArray = hasDividerMode.value\n ? filterWithDividerGroups(sourceData)\n : sourceData.filter((item) => matchesSearchTerm(item))\n matchingItems.value = matchedArray\n\n const shouldLimitItems = props.maxItems !== undefined && props.maxItems > 0\n const effectiveLimit = shouldLimitItems ? (visibleItemsLimit.value ?? props.maxItems) : null\n\n if (isMultiple.value && showSelectedOnly.value) {\n const selectedOnlyItems = matchedArray.filter((item) => isItemSelected(item))\n displayedItems.value = effectiveLimit !== null ? selectedOnlyItems.slice(0, effectiveLimit) : selectedOnlyItems\n } else {\n displayedItems.value = effectiveLimit !== null ? matchedArray.slice(0, effectiveLimit) : matchedArray\n }\n\n const totalMatchingCount = matchingItems.value.filter(\n (item) => props.dividerSelectable || !isDividerItem(item),\n ).length\n onTotal(totalMatchingCount)\n }\n\n const resetVisibleItemsLimit = () => {\n visibleItemsLimit.value = props.maxItems && props.maxItems > 0 ? props.maxItems : null\n }\n\n const syncSelectedItemsWithItems = () => {\n const currentItems = props.items ?? []\n const currentIds = new Set(currentItems.map((item) => getItemIdentifier(item)))\n selectedItems.value = selectedItems.value.filter((item) => currentIds.has(getItemIdentifier(item)))\n }\n\n const hasInternalMoreItems = computed(() => matchingItems.value.length > displayedItems.value.length)\n const hasMoreServerPages = computed(() => {\n if (props.page === undefined || props.totalPages === undefined) return false\n return props.page < props.totalPages\n })\n const shouldShowLoadMore = computed(() => {\n if (isMultiple.value && showSelectedOnly.value) return false\n if (hasInternalMoreItems.value) return true\n if (hasMoreServerPages.value) return true\n if (props.maxItems && props.maxItems > 0) return false\n return props.showLoadMore\n })\n\n const handleInternalLoadMore = (): boolean => {\n if (props.maxItems && props.maxItems > 0 && hasInternalMoreItems.value) {\n visibleItemsLimit.value = (visibleItemsLimit.value ?? props.maxItems) + props.maxItems\n return true\n }\n return false\n }\n\n return {\n displayedItems,\n filterAndPaginate,\n getItemIdentifier,\n isDividerItem,\n isItemSelected,\n optionPaddingStyle,\n sourceItems,\n resetVisibleItemsLimit,\n shouldShowLoadMore,\n handleInternalLoadMore,\n syncSelectedItemsWithItems,\n }\n}\n"],"mappings":";;;;AAOA,IAAa,2BAA2B,EACtC,OACA,cACA,YACA,oBACA,kBACA,eACA,YACA,YAUI;CACJ,MAAM,EAAE,QAAQ,cAAc,MAAM,WAAW;CAC/C,MAAM,gBAAgB,IAAwB,CAAC,CAAC;CAChD,MAAM,iBAAiB,IAAwB,CAAC,CAAC;CACjD,MAAM,oBAAoB,IAAmB,MAAM,YAAY,MAAM,WAAW,IAAI,MAAM,WAAW,IAAI;CACzG,MAAM,iBAAiB,eAA6B,aAAa,MAAM,YAAY,CAAC,CAAC,WAAW,IAAI,IAAI,OAAO,IAAK;CAEpH,MAAM,iBAAiB,UAA4B;EACjD,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,KAAK,SAAS,cAAc,IAAI,CAAC;EAGhD,IAAI,SAAS,OAAO,UAAU,UAAU;GACtC,MAAM,eAAwC,CAAC;GAC/C,OAAO,KAAK,KAAgC,CAAC,CAC1C,KAAK,CAAC,CACN,SAAS,QAAQ;IAChB,aAAa,OAAO,cAAe,MAAkC,IAAI;GAC3E,CAAC;GACH,OAAO;EACT;EAEA,OAAO;CACT;CAEA,MAAM,qBAAqB,SAAmC;EAC5D,MAAM,EAAE,YAAY;EACpB,IAAI,WAAW,KAAK,aAAa,KAAA,GAC/B,OAAO,OAAO,KAAK,QAAQ;EAE7B,OAAO,KAAK,UAAU,cAAc,IAAI,CAAC;CAC3C;CAEA,MAAM,iBAAiB,SAAoC;EAGzD,OADqB,KADA,MAAM,gBAAgB,iBAEnB,QAAQ,KAAK,SAAS;CAChD;CAEA,MAAM,kBAAkB,SAAoC;EAC1D,MAAM,SAAS,kBAAkB,IAAI;EACrC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AQ,cAAc,MAAM,QAAQ,SAAS,WAAW,IAAI,kBAAkB,IAAI,CAAC,CAAC;CACpG;CAEA,MAAM,uBAAuB,eAAe,cAAc,MAAM,SAAS,eAAe,MAAM,MAAM;CACpG,MAAM,qBAAqB,eAAe;EACxC,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,eAAe,KAAA,GAAW,OAAO;EACvE,OAAO,MAAM,OAAO,MAAM;CAC5B,CAAC;CACD,MAAM,qBAAqB,eAAe;EACxC,IAAI,WAAW,SAAS,iBAAiB,OAAO,OAAO;EACvD,IAAI,qBAAqB,OAAO,OAAO;EACvC,IAAI,mBAAmB,OAAO,OAAO;EACrC,IAAI,MAAM,YAAY,MAAM,WAAW,GAAG,OAAO;EACjD,OAAO,MAAM;CACf,CAAC;CAED,MAAM,+BAAwC;EAC5C,IAAI,MAAM,YAAY,MAAM,WAAW,KAAK,qBAAqB,OAAO;GACtE,kBAAkB,SAAS,kBAAkB,SAAS,MAAM,YAAY,MAAM;GAC9E,OAAO;EACT;EACA,OAAO;CACT;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import FdsSnackbar_vue_vue_type_script_setup_true_lang_default from "./FdsSnackbar.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/components/FdsSnackbar/FdsSnackbar.vue
|
|
3
|
+
var FdsSnackbar_default = FdsSnackbar_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { FdsSnackbar_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=FdsSnackbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FdsSnackbar.js","names":["_sfc_main"],"sources":["../../../src/components/FdsSnackbar/FdsSnackbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { onBeforeUnmount, onMounted } from 'vue'\nimport { useFdsI18n } from '../../plugin/useFdsI18n'\nimport FdsToastMessageCard from '../FdsToastMessage/FdsToastMessageCard.vue'\nimport FdsToastRegions from '../FdsToastMessage/FdsToastRegions.vue'\nimport { getReadingDuration } from '../FdsToastMessage/getReadingDuration'\nimport type { FdsSnackbarItem, FdsSnackbarProps } from './types'\nimport { useSnackbar, useSnackbarContainer } from './useSnackbar'\n\nwithDefaults(defineProps<FdsSnackbarProps>(), {\n position: 'bottom-center',\n duration: 10000,\n})\n\nconst { snackbars, dismiss } = useSnackbar()\nconst isActiveContainer = useSnackbarContainer()\nconst { t } = useFdsI18n()\n\nconst visibleSnackbarSelector = '.fds-toast:not(.fds-toast-leave-active) [data-fds-snackbar]'\nlet focusBeforeSnackbar: HTMLElement | null = null\n\nfunction focusSnackbarAction(event: KeyboardEvent) {\n const isShortcut = event.altKey && event.code === 'KeyT' && !event.ctrlKey && !event.metaKey\n if (!isShortcut || !isActiveContainer.value) return\n const actionButton = document.querySelector<HTMLElement>(`${visibleSnackbarSelector} button`)\n if (!actionButton) return\n event.preventDefault()\n const { activeElement } = document\n if (activeElement instanceof HTMLElement && !activeElement.closest('[data-fds-snackbar]')) {\n focusBeforeSnackbar = activeElement\n }\n actionButton.focus()\n}\n\nfunction closeSnackbar(id: number) {\n const snackbarHasFocus = document.activeElement?.closest('[data-fds-snackbar]') != null\n dismiss(id)\n if (snackbarHasFocus) focusBeforeSnackbar?.focus()\n focusBeforeSnackbar = null\n}\n\nfunction handleAction(snackbar: FdsSnackbarItem) {\n snackbar.action.onClick()\n closeSnackbar(snackbar.id)\n}\n\nonMounted(() => window.addEventListener('keydown', focusSnackbarAction))\nonBeforeUnmount(() => window.removeEventListener('keydown', focusSnackbarAction))\n</script>\n\n<template>\n <FdsToastRegions\n v-if=\"isActiveContainer\"\n :items=\"snackbars\"\n :position=\"position\"\n :max=\"1\"\n widthClass=\"sm:w-xl\"\n >\n <template #item=\"{ item }\">\n <FdsToastMessageCard\n :message=\"item.message\"\n :type=\"item.type ?? 'info'\"\n :duration=\"item.duration ?? getReadingDuration(item.message, duration)\"\n :closeable=\"item.closeable ?? true\"\n :actionLabel=\"item.action.label\"\n :screenReaderHint=\"t('FdsSnackbar.focusHint')\"\n :dataTestid=\"item.dataTestid\"\n v-bind=\"{ 'data-fds-snackbar': '' }\"\n @action=\"handleAction(item)\"\n @close=\"closeSnackbar(item.id)\"\n />\n </template>\n </FdsToastRegions>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FdsSnackbarProps } from './types';
|
|
2
|
+
declare const __VLS_export: import('vue').DefineComponent<FdsSnackbarProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<FdsSnackbarProps> & Readonly<{}>, {
|
|
3
|
+
duration: number;
|
|
4
|
+
position: import('../..').FdsToastMessagePosition;
|
|
5
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
6
|
+
declare const _default: typeof __VLS_export;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useFdsI18n } from "../../plugin/useFdsI18n.js";
|
|
2
|
+
import FdsToastMessageCard_default from "../FdsToastMessage/FdsToastMessageCard.js";
|
|
3
|
+
import FdsToastRegions_default from "../FdsToastMessage/FdsToastRegions.js";
|
|
4
|
+
import { getReadingDuration } from "../FdsToastMessage/getReadingDuration.js";
|
|
5
|
+
import { useSnackbar, useSnackbarContainer } from "./useSnackbar.js";
|
|
6
|
+
import { createBlock, createCommentVNode, createVNode, defineComponent, mergeProps, onBeforeUnmount, onMounted, openBlock, unref, withCtx } from "vue";
|
|
7
|
+
// src/components/FdsSnackbar/FdsSnackbar.vue?vue&type=script&setup=true&lang.ts
|
|
8
|
+
var visibleSnackbarSelector = ".fds-toast:not(.fds-toast-leave-active) [data-fds-snackbar]";
|
|
9
|
+
var FdsSnackbar_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
10
|
+
__name: "FdsSnackbar",
|
|
11
|
+
props: {
|
|
12
|
+
position: { default: "bottom-center" },
|
|
13
|
+
duration: { default: 1e4 }
|
|
14
|
+
},
|
|
15
|
+
setup(__props) {
|
|
16
|
+
const { snackbars, dismiss } = useSnackbar();
|
|
17
|
+
const isActiveContainer = useSnackbarContainer();
|
|
18
|
+
const { t } = useFdsI18n();
|
|
19
|
+
let focusBeforeSnackbar = null;
|
|
20
|
+
function focusSnackbarAction(event) {
|
|
21
|
+
if (!(event.altKey && event.code === "KeyT" && !event.ctrlKey && !event.metaKey) || !isActiveContainer.value) return;
|
|
22
|
+
const actionButton = document.querySelector(`${visibleSnackbarSelector} button`);
|
|
23
|
+
if (!actionButton) return;
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
const { activeElement } = document;
|
|
26
|
+
if (activeElement instanceof HTMLElement && !activeElement.closest("[data-fds-snackbar]")) focusBeforeSnackbar = activeElement;
|
|
27
|
+
actionButton.focus();
|
|
28
|
+
}
|
|
29
|
+
function closeSnackbar(id) {
|
|
30
|
+
const snackbarHasFocus = document.activeElement?.closest("[data-fds-snackbar]") != null;
|
|
31
|
+
dismiss(id);
|
|
32
|
+
if (snackbarHasFocus) focusBeforeSnackbar?.focus();
|
|
33
|
+
focusBeforeSnackbar = null;
|
|
34
|
+
}
|
|
35
|
+
function handleAction(snackbar) {
|
|
36
|
+
snackbar.action.onClick();
|
|
37
|
+
closeSnackbar(snackbar.id);
|
|
38
|
+
}
|
|
39
|
+
onMounted(() => window.addEventListener("keydown", focusSnackbarAction));
|
|
40
|
+
onBeforeUnmount(() => window.removeEventListener("keydown", focusSnackbarAction));
|
|
41
|
+
return (_ctx, _cache) => {
|
|
42
|
+
return unref(isActiveContainer) ? (openBlock(), createBlock(FdsToastRegions_default, {
|
|
43
|
+
key: 0,
|
|
44
|
+
items: unref(snackbars),
|
|
45
|
+
position: __props.position,
|
|
46
|
+
max: 1,
|
|
47
|
+
widthClass: "sm:w-xl"
|
|
48
|
+
}, {
|
|
49
|
+
item: withCtx(({ item }) => [createVNode(FdsToastMessageCard_default, mergeProps({
|
|
50
|
+
message: item.message,
|
|
51
|
+
type: item.type ?? "info",
|
|
52
|
+
duration: item.duration ?? unref(getReadingDuration)(item.message, __props.duration),
|
|
53
|
+
closeable: item.closeable ?? true,
|
|
54
|
+
actionLabel: item.action.label,
|
|
55
|
+
screenReaderHint: unref(t)("FdsSnackbar.focusHint"),
|
|
56
|
+
dataTestid: item.dataTestid
|
|
57
|
+
}, { "data-fds-snackbar": "" }, {
|
|
58
|
+
onAction: ($event) => handleAction(item),
|
|
59
|
+
onClose: ($event) => closeSnackbar(item.id)
|
|
60
|
+
}), null, 16, [
|
|
61
|
+
"message",
|
|
62
|
+
"type",
|
|
63
|
+
"duration",
|
|
64
|
+
"closeable",
|
|
65
|
+
"actionLabel",
|
|
66
|
+
"screenReaderHint",
|
|
67
|
+
"dataTestid",
|
|
68
|
+
"onAction",
|
|
69
|
+
"onClose"
|
|
70
|
+
])]),
|
|
71
|
+
_: 1
|
|
72
|
+
}, 8, ["items", "position"])) : createCommentVNode("", true);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
export { FdsSnackbar_vue_vue_type_script_setup_true_lang_default as default };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=FdsSnackbar.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FdsSnackbar.vue_vue_type_script_setup_true_lang.js","names":["_unref","_openBlock","_createBlock","FdsToastRegions","_withCtx","_createVNode","FdsToastMessageCard","_mergeProps","_createCommentVNode"],"sources":["../../../src/components/FdsSnackbar/FdsSnackbar.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { onBeforeUnmount, onMounted } from 'vue'\nimport { useFdsI18n } from '../../plugin/useFdsI18n'\nimport FdsToastMessageCard from '../FdsToastMessage/FdsToastMessageCard.vue'\nimport FdsToastRegions from '../FdsToastMessage/FdsToastRegions.vue'\nimport { getReadingDuration } from '../FdsToastMessage/getReadingDuration'\nimport type { FdsSnackbarItem, FdsSnackbarProps } from './types'\nimport { useSnackbar, useSnackbarContainer } from './useSnackbar'\n\nwithDefaults(defineProps<FdsSnackbarProps>(), {\n position: 'bottom-center',\n duration: 10000,\n})\n\nconst { snackbars, dismiss } = useSnackbar()\nconst isActiveContainer = useSnackbarContainer()\nconst { t } = useFdsI18n()\n\nconst visibleSnackbarSelector = '.fds-toast:not(.fds-toast-leave-active) [data-fds-snackbar]'\nlet focusBeforeSnackbar: HTMLElement | null = null\n\nfunction focusSnackbarAction(event: KeyboardEvent) {\n const isShortcut = event.altKey && event.code === 'KeyT' && !event.ctrlKey && !event.metaKey\n if (!isShortcut || !isActiveContainer.value) return\n const actionButton = document.querySelector<HTMLElement>(`${visibleSnackbarSelector} button`)\n if (!actionButton) return\n event.preventDefault()\n const { activeElement } = document\n if (activeElement instanceof HTMLElement && !activeElement.closest('[data-fds-snackbar]')) {\n focusBeforeSnackbar = activeElement\n }\n actionButton.focus()\n}\n\nfunction closeSnackbar(id: number) {\n const snackbarHasFocus = document.activeElement?.closest('[data-fds-snackbar]') != null\n dismiss(id)\n if (snackbarHasFocus) focusBeforeSnackbar?.focus()\n focusBeforeSnackbar = null\n}\n\nfunction handleAction(snackbar: FdsSnackbarItem) {\n snackbar.action.onClick()\n closeSnackbar(snackbar.id)\n}\n\nonMounted(() => window.addEventListener('keydown', focusSnackbarAction))\nonBeforeUnmount(() => window.removeEventListener('keydown', focusSnackbarAction))\n</script>\n\n<template>\n <FdsToastRegions\n v-if=\"isActiveContainer\"\n :items=\"snackbars\"\n :position=\"position\"\n :max=\"1\"\n widthClass=\"sm:w-xl\"\n >\n <template #item=\"{ item }\">\n <FdsToastMessageCard\n :message=\"item.message\"\n :type=\"item.type ?? 'info'\"\n :duration=\"item.duration ?? getReadingDuration(item.message, duration)\"\n :closeable=\"item.closeable ?? true\"\n :actionLabel=\"item.action.label\"\n :screenReaderHint=\"t('FdsSnackbar.focusHint')\"\n :dataTestid=\"item.dataTestid\"\n v-bind=\"{ 'data-fds-snackbar': '' }\"\n @action=\"handleAction(item)\"\n @close=\"closeSnackbar(item.id)\"\n />\n </template>\n </FdsToastRegions>\n</template>\n"],"mappings":";;;;;;;AAkBA,IAAM,0BAA0B;;;;;;;;EAJhC,MAAM,EAAE,WAAW,YAAY,YAAY;EAC3C,MAAM,oBAAoB,qBAAqB;EAC/C,MAAM,EAAE,MAAM,WAAW;EAGzB,IAAI,sBAA0C;EAE9C,SAAS,oBAAoB,OAAsB;GAEjD,IAAI,EADe,MAAM,UAAU,MAAM,SAAS,UAAU,CAAC,MAAM,WAAW,CAAC,MAAM,YAClE,CAAC,kBAAkB,OAAO;GAC7C,MAAM,eAAe,SAAS,cAA2B,GAAG,wBAAwB,QAAQ;GAC5F,IAAI,CAAC,cAAc;GACnB,MAAM,eAAe;GACrB,MAAM,EAAE,kBAAkB;GAC1B,IAAI,yBAAyB,eAAe,CAAC,cAAc,QAAQ,qBAAqB,GACtF,sBAAsB;GAExB,aAAa,MAAM;EACrB;EAEA,SAAS,cAAc,IAAY;GACjC,MAAM,mBAAmB,SAAS,eAAe,QAAQ,qBAAqB,KAAK;GACnF,QAAQ,EAAE;GACV,IAAI,kBAAkB,qBAAqB,MAAM;GACjD,sBAAsB;EACxB;EAEA,SAAS,aAAa,UAA2B;GAC/C,SAAS,OAAO,QAAQ;GACxB,cAAc,SAAS,EAAE;EAC3B;EAEA,gBAAgB,OAAO,iBAAiB,WAAW,mBAAmB,CAAC;EACvE,sBAAsB,OAAO,oBAAoB,WAAW,mBAAmB,CAAC;;GAKtE,OAAAA,MAAA,iBAAA,KADRC,UAAA,GAAAC,YAqBkBC,yBAAA;;IAnBf,OAAOH,MAAA,SAAA;IACP,UAAU,QAAA;IACV,KAAK;IACN,YAAW;;IAEA,MAAII,SAYX,EAZe,WAAI,CACrBC,YAWEC,6BAXFC,WAWE;KAVC,SAAS,KAAK;KACd,MAAM,KAAK,QAAI;KACf,UAAU,KAAK,YAAYP,MAAA,kBAAA,CAAkB,CAAC,KAAK,SAAS,QAAA,QAAQ;KACpE,WAAW,KAAK,aAAS;KACzB,aAAa,KAAK,OAAO;KACzB,kBAAkBA,MAAA,CAAA,CAAC,CAAA,uBAAA;KACnB,YAAY,KAAK;IACV,GAAA,EAAA,qBAAA,GAAA,GAA2B;KAClC,WAAM,WAAE,aAAa,IAAI;KACzB,UAAK,WAAE,cAAc,KAAK,EAAE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FdsToastMessageOptions, FdsToastMessagePosition } from '../FdsToastMessage/types';
|
|
2
|
+
export interface FdsSnackbarAction {
|
|
3
|
+
label: string;
|
|
4
|
+
onClick: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface FdsSnackbarOptions extends Omit<FdsToastMessageOptions, 'heading'> {
|
|
7
|
+
action: FdsSnackbarAction;
|
|
8
|
+
}
|
|
9
|
+
export interface FdsSnackbarItem extends FdsSnackbarOptions {
|
|
10
|
+
id: number;
|
|
11
|
+
}
|
|
12
|
+
export type FdsSnackbarShortcutOptions = Omit<FdsSnackbarOptions, 'message' | 'type'>;
|
|
13
|
+
export interface FdsSnackbarProps {
|
|
14
|
+
position?: FdsToastMessagePosition;
|
|
15
|
+
duration?: number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FdsSnackbarOptions } from './types';
|
|
2
|
+
export declare function useSnackbar(): {
|
|
3
|
+
snackbars: Readonly<import('vue').ShallowRef<(FdsSnackbarOptions & {
|
|
4
|
+
id: number;
|
|
5
|
+
})[], (FdsSnackbarOptions & {
|
|
6
|
+
id: number;
|
|
7
|
+
})[]>>;
|
|
8
|
+
show: (options: FdsSnackbarOptions) => number;
|
|
9
|
+
dismiss: (id: number) => void;
|
|
10
|
+
clear: () => void;
|
|
11
|
+
success: (message: string, options: {
|
|
12
|
+
dataTestid?: string | undefined;
|
|
13
|
+
closeable?: boolean | undefined;
|
|
14
|
+
action: import('./types').FdsSnackbarAction;
|
|
15
|
+
duration?: number | undefined;
|
|
16
|
+
position?: import('../..').FdsToastMessagePosition | undefined;
|
|
17
|
+
}) => number;
|
|
18
|
+
info: (message: string, options: {
|
|
19
|
+
dataTestid?: string | undefined;
|
|
20
|
+
closeable?: boolean | undefined;
|
|
21
|
+
action: import('./types').FdsSnackbarAction;
|
|
22
|
+
duration?: number | undefined;
|
|
23
|
+
position?: import('../..').FdsToastMessagePosition | undefined;
|
|
24
|
+
}) => number;
|
|
25
|
+
warning: (message: string, options: {
|
|
26
|
+
dataTestid?: string | undefined;
|
|
27
|
+
closeable?: boolean | undefined;
|
|
28
|
+
action: import('./types').FdsSnackbarAction;
|
|
29
|
+
duration?: number | undefined;
|
|
30
|
+
position?: import('../..').FdsToastMessagePosition | undefined;
|
|
31
|
+
}) => number;
|
|
32
|
+
error: (message: string, options: {
|
|
33
|
+
dataTestid?: string | undefined;
|
|
34
|
+
closeable?: boolean | undefined;
|
|
35
|
+
action: import('./types').FdsSnackbarAction;
|
|
36
|
+
duration?: number | undefined;
|
|
37
|
+
position?: import('../..').FdsToastMessagePosition | undefined;
|
|
38
|
+
}) => number;
|
|
39
|
+
};
|
|
40
|
+
export declare const useSnackbarContainer: () => import('vue').ComputedRef<boolean>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createMessageQueue } from "../FdsToastMessage/createMessageQueue.js";
|
|
2
|
+
// src/components/FdsSnackbar/useSnackbar.ts
|
|
3
|
+
var snackbarQueue = createMessageQueue();
|
|
4
|
+
function useSnackbar() {
|
|
5
|
+
return {
|
|
6
|
+
snackbars: snackbarQueue.items,
|
|
7
|
+
show: snackbarQueue.show,
|
|
8
|
+
dismiss: snackbarQueue.dismiss,
|
|
9
|
+
clear: snackbarQueue.clear,
|
|
10
|
+
success: snackbarQueue.success,
|
|
11
|
+
info: snackbarQueue.info,
|
|
12
|
+
warning: snackbarQueue.warning,
|
|
13
|
+
error: snackbarQueue.error
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
var useSnackbarContainer = snackbarQueue.useContainer;
|
|
17
|
+
export { useSnackbar, useSnackbarContainer };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=useSnackbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSnackbar.js","names":[],"sources":["../../../src/components/FdsSnackbar/useSnackbar.ts"],"sourcesContent":["import { createMessageQueue } from '../FdsToastMessage/createMessageQueue'\nimport type { FdsSnackbarOptions } from './types'\n\nconst snackbarQueue = createMessageQueue<FdsSnackbarOptions>()\n\nexport function useSnackbar() {\n return {\n snackbars: snackbarQueue.items,\n show: snackbarQueue.show,\n dismiss: snackbarQueue.dismiss,\n clear: snackbarQueue.clear,\n success: snackbarQueue.success,\n info: snackbarQueue.info,\n warning: snackbarQueue.warning,\n error: snackbarQueue.error,\n }\n}\n\nexport const useSnackbarContainer = snackbarQueue.useContainer\n"],"mappings":";;AAGA,IAAM,gBAAgB,mBAAuC;AAE7D,SAAgB,cAAc;CAC5B,OAAO;EACL,WAAW,cAAc;EACzB,MAAM,cAAc;EACpB,SAAS,cAAc;EACvB,OAAO,cAAc;EACrB,SAAS,cAAc;EACvB,MAAM,cAAc;EACpB,SAAS,cAAc;EACvB,OAAO,cAAc;CACvB;AACF;AAEA,IAAa,uBAAuB,cAAc"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import FdsToastMessage_vue_vue_type_script_setup_true_lang_default from "./FdsToastMessage.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/components/FdsToastMessage/FdsToastMessage.vue
|
|
3
|
+
var FdsToastMessage_default = FdsToastMessage_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { FdsToastMessage_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=FdsToastMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FdsToastMessage.js","names":["_sfc_main"],"sources":["../../../src/components/FdsToastMessage/FdsToastMessage.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport FdsToastMessageCard from './FdsToastMessageCard.vue'\nimport FdsToastRegions from './FdsToastRegions.vue'\nimport { getReadingDuration } from './getReadingDuration'\nimport type { FdsToastMessageItem, FdsToastMessageProps } from './types'\nimport { useToastMessage, useToastMessageContainer } from './useToastMessage'\n\nwithDefaults(defineProps<FdsToastMessageProps>(), {\n position: 'bottom-right',\n duration: 5000,\n max: 3,\n})\n\nconst { toasts, dismiss } = useToastMessage()\nconst isActiveContainer = useToastMessageContainer()\n\nfunction getDuration(toast: FdsToastMessageItem, minimumDuration: number) {\n if (toast.duration !== undefined) return toast.duration\n if (toast.type === 'error' || toast.type === 'warning') return 0\n return getReadingDuration(`${toast.heading ?? ''} ${toast.message}`, minimumDuration)\n}\n</script>\n\n<template>\n <FdsToastRegions\n v-if=\"isActiveContainer\"\n :items=\"toasts\"\n :position=\"position\"\n :max=\"max\"\n widthClass=\"sm:w-96\"\n >\n <template #item=\"{ item }\">\n <FdsToastMessageCard\n :message=\"item.message\"\n :heading=\"item.heading\"\n :type=\"item.type ?? 'info'\"\n :duration=\"getDuration(item, duration)\"\n :closeable=\"item.closeable ?? true\"\n :dataTestid=\"item.dataTestid\"\n @close=\"dismiss(item.id)\"\n />\n </template>\n </FdsToastRegions>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FdsToastMessageProps } from './types';
|
|
2
|
+
declare const __VLS_export: import('vue').DefineComponent<FdsToastMessageProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<FdsToastMessageProps> & Readonly<{}>, {
|
|
3
|
+
max: number;
|
|
4
|
+
duration: number;
|
|
5
|
+
position: import('./types').FdsToastMessagePosition;
|
|
6
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const _default: typeof __VLS_export;
|
|
8
|
+
export default _default;
|
package/dist/components/FdsToastMessage/FdsToastMessage.vue_vue_type_script_setup_true_lang.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import FdsToastMessageCard_default from "./FdsToastMessageCard.js";
|
|
2
|
+
import FdsToastRegions_default from "./FdsToastRegions.js";
|
|
3
|
+
import { getReadingDuration } from "./getReadingDuration.js";
|
|
4
|
+
import { useToastMessage, useToastMessageContainer } from "./useToastMessage.js";
|
|
5
|
+
import { createBlock, createCommentVNode, createVNode, defineComponent, openBlock, unref, withCtx } from "vue";
|
|
6
|
+
// src/components/FdsToastMessage/FdsToastMessage.vue?vue&type=script&setup=true&lang.ts
|
|
7
|
+
var FdsToastMessage_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
8
|
+
__name: "FdsToastMessage",
|
|
9
|
+
props: {
|
|
10
|
+
position: { default: "bottom-right" },
|
|
11
|
+
duration: { default: 5e3 },
|
|
12
|
+
max: { default: 3 }
|
|
13
|
+
},
|
|
14
|
+
setup(__props) {
|
|
15
|
+
const { toasts, dismiss } = useToastMessage();
|
|
16
|
+
const isActiveContainer = useToastMessageContainer();
|
|
17
|
+
function getDuration(toast, minimumDuration) {
|
|
18
|
+
if (toast.duration !== void 0) return toast.duration;
|
|
19
|
+
if (toast.type === "error" || toast.type === "warning") return 0;
|
|
20
|
+
return getReadingDuration(`${toast.heading ?? ""} ${toast.message}`, minimumDuration);
|
|
21
|
+
}
|
|
22
|
+
return (_ctx, _cache) => {
|
|
23
|
+
return unref(isActiveContainer) ? (openBlock(), createBlock(FdsToastRegions_default, {
|
|
24
|
+
key: 0,
|
|
25
|
+
items: unref(toasts),
|
|
26
|
+
position: __props.position,
|
|
27
|
+
max: __props.max,
|
|
28
|
+
widthClass: "sm:w-96"
|
|
29
|
+
}, {
|
|
30
|
+
item: withCtx(({ item }) => [createVNode(FdsToastMessageCard_default, {
|
|
31
|
+
message: item.message,
|
|
32
|
+
heading: item.heading,
|
|
33
|
+
type: item.type ?? "info",
|
|
34
|
+
duration: getDuration(item, __props.duration),
|
|
35
|
+
closeable: item.closeable ?? true,
|
|
36
|
+
dataTestid: item.dataTestid,
|
|
37
|
+
onClose: ($event) => unref(dismiss)(item.id)
|
|
38
|
+
}, null, 8, [
|
|
39
|
+
"message",
|
|
40
|
+
"heading",
|
|
41
|
+
"type",
|
|
42
|
+
"duration",
|
|
43
|
+
"closeable",
|
|
44
|
+
"dataTestid",
|
|
45
|
+
"onClose"
|
|
46
|
+
])]),
|
|
47
|
+
_: 1
|
|
48
|
+
}, 8, [
|
|
49
|
+
"items",
|
|
50
|
+
"position",
|
|
51
|
+
"max"
|
|
52
|
+
])) : createCommentVNode("", true);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export { FdsToastMessage_vue_vue_type_script_setup_true_lang_default as default };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=FdsToastMessage.vue_vue_type_script_setup_true_lang.js.map
|
package/dist/components/FdsToastMessage/FdsToastMessage.vue_vue_type_script_setup_true_lang.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FdsToastMessage.vue_vue_type_script_setup_true_lang.js","names":["_unref","_openBlock","_createBlock","FdsToastRegions","_withCtx","_createVNode","FdsToastMessageCard","_createCommentVNode"],"sources":["../../../src/components/FdsToastMessage/FdsToastMessage.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport FdsToastMessageCard from './FdsToastMessageCard.vue'\nimport FdsToastRegions from './FdsToastRegions.vue'\nimport { getReadingDuration } from './getReadingDuration'\nimport type { FdsToastMessageItem, FdsToastMessageProps } from './types'\nimport { useToastMessage, useToastMessageContainer } from './useToastMessage'\n\nwithDefaults(defineProps<FdsToastMessageProps>(), {\n position: 'bottom-right',\n duration: 5000,\n max: 3,\n})\n\nconst { toasts, dismiss } = useToastMessage()\nconst isActiveContainer = useToastMessageContainer()\n\nfunction getDuration(toast: FdsToastMessageItem, minimumDuration: number) {\n if (toast.duration !== undefined) return toast.duration\n if (toast.type === 'error' || toast.type === 'warning') return 0\n return getReadingDuration(`${toast.heading ?? ''} ${toast.message}`, minimumDuration)\n}\n</script>\n\n<template>\n <FdsToastRegions\n v-if=\"isActiveContainer\"\n :items=\"toasts\"\n :position=\"position\"\n :max=\"max\"\n widthClass=\"sm:w-96\"\n >\n <template #item=\"{ item }\">\n <FdsToastMessageCard\n :message=\"item.message\"\n :heading=\"item.heading\"\n :type=\"item.type ?? 'info'\"\n :duration=\"getDuration(item, duration)\"\n :closeable=\"item.closeable ?? true\"\n :dataTestid=\"item.dataTestid\"\n @close=\"dismiss(item.id)\"\n />\n </template>\n </FdsToastRegions>\n</template>\n"],"mappings":";;;;;;;;;;;;;;EAaA,MAAM,EAAE,QAAQ,YAAY,gBAAgB;EAC5C,MAAM,oBAAoB,yBAAyB;EAEnD,SAAS,YAAY,OAA4B,iBAAyB;GACxE,IAAI,MAAM,aAAa,KAAA,GAAW,OAAO,MAAM;GAC/C,IAAI,MAAM,SAAS,WAAW,MAAM,SAAS,WAAW,OAAO;GAC/D,OAAO,mBAAmB,GAAG,MAAM,WAAW,GAAG,GAAG,MAAM,WAAW,eAAe;EACtF;;GAKU,OAAAA,MAAA,iBAAA,KADRC,UAAA,GAAAC,YAkBkBC,yBAAA;;IAhBf,OAAOH,MAAA,MAAA;IACP,UAAU,QAAA;IACV,KAAK,QAAA;IACN,YAAW;;IAEA,MAAII,SASX,EATe,WAAI,CACrBC,YAQEC,6BAAA;KAPC,SAAS,KAAK;KACd,SAAS,KAAK;KACd,MAAM,KAAK,QAAI;KACf,UAAU,YAAY,MAAM,QAAA,QAAQ;KACpC,WAAW,KAAK,aAAS;KACzB,YAAY,KAAK;KACjB,UAAK,WAAEN,MAAA,OAAA,CAAO,CAAC,KAAK,EAAE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import FdsToastMessageCard_vue_vue_type_script_setup_true_lang_default from "./FdsToastMessageCard.vue_vue_type_script_setup_true_lang.js";
|
|
2
|
+
// src/components/FdsToastMessage/FdsToastMessageCard.vue
|
|
3
|
+
var FdsToastMessageCard_default = FdsToastMessageCard_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
export { FdsToastMessageCard_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=FdsToastMessageCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FdsToastMessageCard.js","names":["_sfc_main"],"sources":["../../../src/components/FdsToastMessage/FdsToastMessageCard.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useFdsI18n } from '../../plugin/useFdsI18n'\nimport FdsButtonIcon from '../Buttons/FdsButtonIcon/FdsButtonIcon.vue'\nimport FdsButtonMinor from '../Buttons/FdsButtonMinor/FdsButtonMinor.vue'\nimport FdsIcon from '../FdsIcon/FdsIcon.vue'\nimport type { FdsIconName } from '../FdsIcon/types'\nimport type { FdsToastMessageType } from './types'\n\nconst props = defineProps<{\n message: string\n heading?: string\n type: FdsToastMessageType\n duration: number\n closeable: boolean\n actionLabel?: string\n screenReaderHint?: string\n dataTestid?: string\n}>()\n\nconst emit = defineEmits<{\n (e: 'close'): void\n (e: 'action'): void\n}>()\n\nconst { t } = useFdsI18n()\n\nconst typeStyles: Record<FdsToastMessageType, { card: string; icon: string; action: string; iconName: FdsIconName }> =\n {\n success: { card: 'bg-green-100 inset-ring-green-300', icon: 'fill-green-700', action: '', iconName: 'success' },\n info: { card: 'bg-blue-100 inset-ring-blue-300', icon: 'fill-blue-700', action: '', iconName: 'information' },\n warning: {\n card: 'bg-yellow-200 inset-ring-yellow-300',\n icon: 'fill-yellow-700',\n action:\n '[&_button]:text-gray-900! [&_button]:underline [&_button]:hover:bg-gray-100! [&_button]:active:bg-gray-200!',\n iconName: 'warning',\n },\n error: { card: 'bg-red-100 inset-ring-red-300', icon: 'fill-red-700', action: '', iconName: 'alert' },\n }\n\nconst style = computed(() => typeStyles[props.type])\n\nconst typeLabel = computed(() => {\n const labels: Record<FdsToastMessageType, string> = {\n success: t('FdsToastMessage.type.success'),\n info: t('FdsToastMessage.type.info'),\n warning: t('FdsToastMessage.type.warning'),\n error: t('FdsToastMessage.type.error'),\n }\n return labels[props.type]\n})\n\nconst isHovered = ref(false)\nconst isFocused = ref(false)\nconst isSwiping = ref(false)\nconst swipeOffset = ref(0)\nlet swipeStartX = 0\nlet swipeStartTime = 0\n\nconst isPaused = computed(() => isHovered.value || isFocused.value || isSwiping.value)\n\nconst cardStyle = computed(() => ({\n transform: swipeOffset.value ? `translateX(${swipeOffset.value}px)` : undefined,\n opacity: swipeOffset.value ? Math.max(0.3, 1 - Math.abs(swipeOffset.value) / 250) : undefined,\n}))\n\nlet remainingTime = props.duration\nlet closeTimer: number | undefined\nlet timerStartedAt = 0\n\nfunction startCloseTimer() {\n if (props.duration <= 0 || closeTimer !== undefined) return\n timerStartedAt = Date.now()\n closeTimer = window.setTimeout(() => emit('close'), remainingTime)\n}\n\nfunction pauseCloseTimer() {\n if (closeTimer === undefined) return\n window.clearTimeout(closeTimer)\n closeTimer = undefined\n remainingTime -= Date.now() - timerStartedAt\n}\n\nwatch(isPaused, (paused) => (paused ? pauseCloseTimer() : startCloseTimer()))\n\nonMounted(startCloseTimer)\n\nonBeforeUnmount(pauseCloseTimer)\n\nfunction handlePointerDown(event: PointerEvent) {\n if (event.pointerType === 'mouse' || (event.target instanceof Element && event.target.closest('button, a'))) return\n isSwiping.value = true\n swipeStartX = event.clientX\n swipeStartTime = event.timeStamp\n}\n\nfunction handlePointerMove(event: PointerEvent) {\n if (!isSwiping.value) return\n const distance = event.clientX - swipeStartX\n if (swipeOffset.value === 0 && Math.abs(distance) < 10) return\n swipeOffset.value = distance\n}\n\nfunction handlePointerUp(event: PointerEvent) {\n if (!isSwiping.value) return\n isSwiping.value = false\n const distance = Math.abs(swipeOffset.value)\n const speed = distance / Math.max(1, event.timeStamp - swipeStartTime)\n if (distance > 100 || (distance > 30 && speed > 0.5)) {\n emit('close')\n return\n }\n swipeOffset.value = 0\n}\n\nfunction handlePointerCancel() {\n isSwiping.value = false\n swipeOffset.value = 0\n}\n\nfunction handleFocusOut(event: FocusEvent) {\n if (event.currentTarget instanceof Element && event.relatedTarget instanceof Node) {\n isFocused.value = event.currentTarget.contains(event.relatedTarget)\n return\n }\n isFocused.value = false\n}\n</script>\n\n<template>\n <div\n :role=\"type === 'error' ? 'alert' : undefined\"\n v-bind=\"{ 'data-testid': dataTestid }\"\n :class=\"[\n 'pointer-events-auto flex items-start gap-3 overflow-hidden rounded-md inset-ring-1 p-4 shadow-lg touch-pan-y',\n style.card,\n isSwiping ? '' : 'transition-[transform,opacity] duration-200 ease-out',\n swipeOffset !== 0 && 'select-none',\n ]\"\n :style=\"cardStyle\"\n @mouseenter=\"isHovered = true\"\n @mouseleave=\"isHovered = false\"\n @focusin=\"isFocused = true\"\n @focusout=\"handleFocusOut\"\n @keydown.esc=\"closeable && emit('close')\"\n @pointerdown=\"handlePointerDown\"\n @pointermove=\"handlePointerMove\"\n @pointerup=\"handlePointerUp\"\n @pointercancel=\"handlePointerCancel\"\n >\n <div class=\"h-7 flex items-center shrink-0\">\n <FdsIcon :name=\"style.iconName\" :size=\"24\" :class=\"style.icon\" aria-hidden=\"true\" />\n </div>\n <div class=\"flex-1 min-w-0 flex flex-col py-0.5 break-words\">\n <span class=\"sr-only\">{{ typeLabel }}</span>\n <span v-if=\"heading\" class=\"font-bold\">{{ heading }}</span>\n <span>{{ message }}</span>\n <span v-if=\"screenReaderHint\" class=\"sr-only\">{{ screenReaderHint }}</span>\n </div>\n <div v-if=\"actionLabel\" class=\"flex flex-col justify-center self-center shrink-0\">\n <FdsButtonMinor :text=\"actionLabel\" :class=\"style.action\" @click=\"emit('action')\" />\n </div>\n <FdsButtonIcon\n v-if=\"closeable\"\n icon=\"cross\"\n :size=\"28\"\n class=\"shrink-0 fill-gray-900! hover:bg-gray-100 active:bg-gray-200\"\n v-bind=\"{ 'aria-label': t('FdsToastMessage.close') }\"\n @click=\"emit('close')\"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FdsToastMessageType } from './types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
message: string;
|
|
4
|
+
heading?: string;
|
|
5
|
+
type: FdsToastMessageType;
|
|
6
|
+
duration: number;
|
|
7
|
+
closeable: boolean;
|
|
8
|
+
actionLabel?: string;
|
|
9
|
+
screenReaderHint?: string;
|
|
10
|
+
dataTestid?: string;
|
|
11
|
+
};
|
|
12
|
+
declare const __VLS_export: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
13
|
+
close: () => any;
|
|
14
|
+
action: () => any;
|
|
15
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
16
|
+
onClose?: (() => any) | undefined;
|
|
17
|
+
onAction?: (() => any) | undefined;
|
|
18
|
+
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
19
|
+
declare const _default: typeof __VLS_export;
|
|
20
|
+
export default _default;
|