@amboss/design-system 1.11.0 → 1.12.1
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/build/cjs/build-tokens/_breakpoints.json.js +4 -1
- package/build/cjs/build-tokens/visualConfig.js +26 -0
- package/build/cjs/src/components/Callout/Callout.js +22 -6
- package/build/cjs/src/components/Form/RadioButton/RadioButton.js +5 -3
- package/build/cjs/src/components/Form/SegmentedControl/SegmentedControl.js +126 -0
- package/build/cjs/src/components/Form/SegmentedControl/SegmentedControlOption.js +216 -0
- package/build/cjs/src/index.js +2 -0
- package/build/cjs/src/shared/mediaQueries.js +2 -2
- package/build/esm/build-tokens/_breakpoints.json.js +2 -2
- package/build/esm/build-tokens/visualConfig.d.ts +13 -0
- package/build/esm/build-tokens/visualConfig.js +26 -0
- package/build/esm/build-tokens/visualConfig.js.map +1 -1
- package/build/esm/src/components/Badge/Badge.js.map +1 -1
- package/build/esm/src/components/Box/Box.js.map +1 -1
- package/build/esm/src/components/Button/Button.js.map +1 -1
- package/build/esm/src/components/Callout/Callout.js +22 -6
- package/build/esm/src/components/Callout/Callout.js.map +1 -1
- package/build/esm/src/components/Card/Card.js.map +1 -1
- package/build/esm/src/components/Card/CardBox.js.map +1 -1
- package/build/esm/src/components/Card/CardHeader/CardHeader.js.map +1 -1
- package/build/esm/src/components/Collapsible/Collapsible.js.map +1 -1
- package/build/esm/src/components/Column/Columns.js.map +1 -1
- package/build/esm/src/components/Container/Container.js.map +1 -1
- package/build/esm/src/components/DataTable/DataTable.js.map +1 -1
- package/build/esm/src/components/DataTable/TableBody.js.map +1 -1
- package/build/esm/src/components/DataTable/TableCell.js.map +1 -1
- package/build/esm/src/components/DataTable/TableHeader.js.map +1 -1
- package/build/esm/src/components/DataTable/useDataTableSort.js.map +1 -1
- package/build/esm/src/components/Divider/Divider.js.map +1 -1
- package/build/esm/src/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/build/esm/src/components/DropdownMenu/MenuItem.js.map +1 -1
- package/build/esm/src/components/Form/Checkbox/Checkbox.js.map +1 -1
- package/build/esm/src/components/Form/FormErrorMessages/FormErrorMessages.js.map +1 -1
- package/build/esm/src/components/Form/FormField/FormField.js.map +1 -1
- package/build/esm/src/components/Form/FormFieldGroup/FormFieldGroup.js.map +1 -1
- package/build/esm/src/components/Form/FormLabelText/FormLabelText.js.map +1 -1
- package/build/esm/src/components/Form/Input/Input.js.map +1 -1
- package/build/esm/src/components/Form/PasswordInput/PasswordInput.js.map +1 -1
- package/build/esm/src/components/Form/Radio/Radio.js.map +1 -1
- package/build/esm/src/components/Form/RadioButton/RadioButton.d.ts +1 -0
- package/build/esm/src/components/Form/RadioButton/RadioButton.js +5 -3
- package/build/esm/src/components/Form/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/src/components/Form/SegmentedControl/SegmentedControl.d.ts +31 -0
- package/build/esm/src/components/Form/SegmentedControl/SegmentedControl.js +119 -0
- package/build/esm/src/components/Form/SegmentedControl/SegmentedControl.js.map +1 -0
- package/build/esm/src/components/Form/SegmentedControl/SegmentedControlOption.d.ts +8 -0
- package/build/esm/src/components/Form/SegmentedControl/SegmentedControlOption.js +210 -0
- package/build/esm/src/components/Form/SegmentedControl/SegmentedControlOption.js.map +1 -0
- package/build/esm/src/components/Form/Select/Select.js.map +1 -1
- package/build/esm/src/components/Form/Textarea/Textarea.js.map +1 -1
- package/build/esm/src/components/Form/Toggle/Toggle.js.map +1 -1
- package/build/esm/src/components/Form/ToggleButton/ToggleButton.js.map +1 -1
- package/build/esm/src/components/Icon/Icon.js.map +1 -1
- package/build/esm/src/components/Inline/Inline.js.map +1 -1
- package/build/esm/src/components/Link/Link.js.map +1 -1
- package/build/esm/src/components/LoadingSpinner/LoadingSpinner.js.map +1 -1
- package/build/esm/src/components/Logo/Logo.js.map +1 -1
- package/build/esm/src/components/MediaItem/MediaItem.js.map +1 -1
- package/build/esm/src/components/MediaViewerBar/MediaViewerBar.js.map +1 -1
- package/build/esm/src/components/Notification/Notification.js.map +1 -1
- package/build/esm/src/components/Pagination/Pagination.js.map +1 -1
- package/build/esm/src/components/Patterns/ButtonGroup/ButtonGroup.js.map +1 -1
- package/build/esm/src/components/Patterns/Modal/Modal.js.map +1 -1
- package/build/esm/src/components/PictogramButton/PictogramButton.js.map +1 -1
- package/build/esm/src/components/Portal/Portal.js.map +1 -1
- package/build/esm/src/components/ProgressBar/ProgressBar.js.map +1 -1
- package/build/esm/src/components/RoundButton/RoundButton.js.map +1 -1
- package/build/esm/src/components/SearchResult/SearchResult.js.map +1 -1
- package/build/esm/src/components/SegmentedProgressBar/SegmentedProgressBar.js.map +1 -1
- package/build/esm/src/components/SegmentedProgressBar/SegmentedProgressBarUtil.js.map +1 -1
- package/build/esm/src/components/Stack/Stack.js.map +1 -1
- package/build/esm/src/components/SubThemeProvider/SubThemeProvider.js.map +1 -1
- package/build/esm/src/components/Tabs/Tabs.js.map +1 -1
- package/build/esm/src/components/Typography/StyledText/StyledText.js.map +1 -1
- package/build/esm/src/components/Typography/Text/Text.js.map +1 -1
- package/build/esm/src/components/Typography/TextClamped/TextClamped.js.map +1 -1
- package/build/esm/src/components/VirtualScrollList/VirtualScrollList.js.map +1 -1
- package/build/esm/src/components/VirtualScrollList/VirtualScrollListReducer.js.map +1 -1
- package/build/esm/src/index.d.ts +1 -0
- package/build/esm/src/index.js +1 -0
- package/build/esm/src/index.js.map +1 -1
- package/build/esm/src/shared/ScreenReaderText.js.map +1 -1
- package/build/esm/src/shared/flattenChildren.js.map +1 -1
- package/build/esm/src/shared/informDeprecation.js.map +1 -1
- package/build/esm/src/shared/mediaQueries.js +2 -2
- package/build/esm/src/shared/mediaQueries.js.map +1 -1
- package/build/esm/src/shared/useAutoPosition.js.map +1 -1
- package/build/esm/src/shared/useKeyboard.js.map +1 -1
- package/build/esm/src/shared/useOnEscapePress.js.map +1 -1
- package/build/esm/src/shared/useOutsideClick.js.map +1 -1
- package/package.json +7 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mediaQueries.js","sources":["../../../../src/shared/mediaQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n ColumnSizes,\n HorizontalAlignment,\n MQ,\n SpaceSizes,\n TextAlignment,\n VerticalAlignment,\n Order,\n ColumnAlignment,\n Hyphens,\n} from \"../types\";\nimport breakpoints from \"../../build-tokens/_breakpoints.json\";\n\ntype MqProp<T> = [\n T | MQ<T>,\n Record<T extends string ? T : never, string | number>\n];\n\n/*\n Although, mq implementation supports any property type, the following types are specified to provide type safety. If you need support for a new type, add it here.\n*/\ntype MqRules = Record<\n string,\n | MqProp<TextAlignment>\n | MqProp<SpaceSizes>\n | MqProp<HorizontalAlignment>\n | MqProp<VerticalAlignment>\n | MqProp<ColumnSizes>\n | MqProp<Order>\n | MqProp<ColumnAlignment>\n | MqProp<Hyphens>\n>;\n\ntype EmotionCssPropertyName = string;\ntype EmotionCssValue = string | number;\ntype EmotionCssDescription = Record<EmotionCssPropertyName, EmotionCssValue>;\ntype MqFunc = (\n rules: MqRules\n) => Record<string, EmotionCssValue | EmotionCssDescription>;\n\n// this thing probably deserves to be a separate library, like facepaint for emotion\nfunction getMq(breakpointRules: string[]): MqFunc {\n const keys = breakpointRules;\n\n return (rules) => {\n const res: Record<string, EmotionCssValue | EmotionCssDescription> = {};\n\n keys.forEach((key: string) => {\n res[key] = {};\n });\n res[`@media screen`] = {};\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Object.entries(rules).forEach(([cssProperty, [prop, map]]: any) => {\n if (Array.isArray(prop)) {\n const sm = prop[0];\n const md = prop[1] || prop[0];\n const lg = prop[2] || prop[1] || prop[0];\n const [s, m, l]: string[] = keys;\n\n (res[s] as EmotionCssDescription)[cssProperty] = map[sm];\n (res[m] as EmotionCssDescription)[cssProperty] = map[md];\n (res[l] as EmotionCssDescription)[cssProperty] = map[lg];\n } else {\n (res[`@media screen`] as EmotionCssDescription)[cssProperty] = map[\n prop as string\n ] as string;\n }\n });\n\n return res;\n };\n}\n\nexport const mq = getMq([\n `@media (max-width: ${breakpoints
|
|
1
|
+
{"version":3,"file":"mediaQueries.js","sources":["../../../../src/shared/mediaQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n ColumnSizes,\n HorizontalAlignment,\n MQ,\n SpaceSizes,\n TextAlignment,\n VerticalAlignment,\n Order,\n ColumnAlignment,\n Hyphens,\n} from \"../types\";\nimport breakpoints from \"../../build-tokens/_breakpoints.json\";\n\ntype MqProp<T> = [\n T | MQ<T>,\n Record<T extends string ? T : never, string | number>\n];\n\n/*\n Although, mq implementation supports any property type, the following types are specified to provide type safety. If you need support for a new type, add it here.\n*/\ntype MqRules = Record<\n string,\n | MqProp<TextAlignment>\n | MqProp<SpaceSizes>\n | MqProp<HorizontalAlignment>\n | MqProp<VerticalAlignment>\n | MqProp<ColumnSizes>\n | MqProp<Order>\n | MqProp<ColumnAlignment>\n | MqProp<Hyphens>\n>;\n\ntype EmotionCssPropertyName = string;\ntype EmotionCssValue = string | number;\ntype EmotionCssDescription = Record<EmotionCssPropertyName, EmotionCssValue>;\ntype MqFunc = (\n rules: MqRules\n) => Record<string, EmotionCssValue | EmotionCssDescription>;\n\n// this thing probably deserves to be a separate library, like facepaint for emotion\nfunction getMq(breakpointRules: string[]): MqFunc {\n const keys = breakpointRules;\n\n return (rules) => {\n const res: Record<string, EmotionCssValue | EmotionCssDescription> = {};\n\n keys.forEach((key: string) => {\n res[key] = {};\n });\n res[`@media screen`] = {};\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Object.entries(rules).forEach(([cssProperty, [prop, map]]: any) => {\n if (Array.isArray(prop)) {\n const sm = prop[0];\n const md = prop[1] || prop[0];\n const lg = prop[2] || prop[1] || prop[0];\n const [s, m, l]: string[] = keys;\n\n (res[s] as EmotionCssDescription)[cssProperty] = map[sm];\n (res[m] as EmotionCssDescription)[cssProperty] = map[md];\n (res[l] as EmotionCssDescription)[cssProperty] = map[lg];\n } else {\n (res[`@media screen`] as EmotionCssDescription)[cssProperty] = map[\n prop as string\n ] as string;\n }\n });\n\n return res;\n };\n}\n\nexport const mq = getMq([\n `@media (max-width: ${breakpoints.medium.value}px)`,\n `@media (min-width: ${breakpoints.medium.value}px) and (max-width: ${breakpoints.large.value}px)`,\n `@media (min-width: ${breakpoints.large.value}px)`,\n]);\n\nfunction getMqValue(breakpointRules: string[]) {\n const keys = breakpointRules;\n return (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rules: Record<EmotionCssPropertyName, EmotionCssValue[] | EmotionCssValue>\n ): Record<string, EmotionCssValue | EmotionCssDescription> => {\n const res: Record<string, EmotionCssValue | EmotionCssDescription> = {};\n keys.forEach((key: string) => {\n res[key] = {};\n });\n res[`@media screen`] = {};\n\n Object.entries(rules).forEach(([cssProperty, cssValues]) => {\n if (Array.isArray(cssValues)) {\n breakpointRules.forEach((breakpoint, index) => {\n let i = index;\n while (!cssValues[i] && i !== 0) {\n i -= 1;\n }\n\n (res[breakpoint] as EmotionCssDescription)[cssProperty] =\n cssValues[i];\n });\n } else {\n (res[`@media screen`] as EmotionCssDescription)[cssProperty] =\n cssValues;\n }\n });\n\n return res;\n };\n}\n\nexport const mqValue = getMqValue([\n `@media (max-width: ${breakpoints.medium.value}px)`,\n `@media (min-width: ${breakpoints.medium.value}px) and (max-width: ${breakpoints.large.value}px)`,\n `@media (min-width: ${breakpoints.large.value}px)`,\n]);\n\nexport function getMediaQueryClasses<T>(\n s: T | MQ<T> | undefined,\n styles: Record<string, string>,\n prefix = \"\"\n): string[] {\n if (s === undefined) return [];\n\n let res;\n if (Array.isArray(s)) {\n const sm = s[0];\n const md = s[1] || s[0];\n const lg = s[2] || s[1] || s[0];\n\n res = [`${sm}-small`, `${md}-medium`, `${lg}-large`];\n } else {\n res = [s as unknown as string];\n }\n\n return res.map((cl) => `${prefix}${cl}`).map((cl) => styles[cl]);\n}\n"],"names":["getMq","breakpointRules","keys","rules","res","forEach","key","Object","entries","_ref","cssProperty","prop","map","Array","isArray","sm","md","lg","s","m","l","mq","breakpoints","medium","value","large","getMqValue","_ref2","cssValues","breakpoint","index","i","mqValue"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoPosition.js","sources":["../../../../src/shared/useAutoPosition.ts"],"sourcesContent":["import { useState, useLayoutEffect, RefObject } from \"react\";\n\nimport { useWindow } from \"./useWindow\";\nimport { useDocument } from \"./useDocument\";\n\nexport type VerticalPosition = \"up\" | \"down\";\nexport type HorizontalPosition = \"left\" | \"right\";\nexport type Position = [VerticalPosition, HorizontalPosition];\n\nexport const useAutoPosition = (\n anchorRef: RefObject<HTMLElement>,\n contentRef: RefObject<HTMLElement>,\n isActive: boolean\n): Position => {\n const [verticalPosition, setVerticalPosition] = useState(\n \"down\" as VerticalPosition\n );\n const [horizontalPosition, setHorizontalPosition] = useState(\n \"left\" as HorizontalPosition\n );\n const document = useDocument();\n const window = useWindow();\n\n useLayoutEffect(() => {\n if (!contentRef) return;\n\n if (isActive) {\n const maxHeight = Math.max(\n document.documentElement.clientHeight || 0,\n window.innerHeight || 0\n );\n\n const rect: DOMRect = contentRef.current.getBoundingClientRect();\n const anchorHeight = anchorRef.current.getBoundingClientRect().height;\n const anchorX = anchorRef.current.getBoundingClientRect().x;\n const screenWidth = window.innerWidth;\n\n const isUp = rect.top + rect.height > maxHeight;\n const isDown = rect.top - anchorHeight < rect.height;\n const isLeft = anchorX > screenWidth / 2;\n const isRight = anchorX < screenWidth / 2;\n\n if (isUp) {\n setVerticalPosition(\"up\");\n } else if (isDown) {\n setVerticalPosition(\"down\");\n }\n\n if (isLeft) {\n setHorizontalPosition(\"left\");\n } else if (isRight) {\n setHorizontalPosition(\"right\");\n }\n } else {\n setVerticalPosition(\"down\");\n setHorizontalPosition(\"left\");\n }\n }, [\n anchorRef,\n contentRef,\n document.documentElement.clientHeight,\n isActive,\n window.innerHeight,\n window.innerWidth,\n ]);\n\n return [verticalPosition, horizontalPosition];\n};\n"],"names":["useAutoPosition","anchorRef","contentRef","isActive","verticalPosition","setVerticalPosition","useState","horizontalPosition","setHorizontalPosition","document","useDocument","window","useWindow","useLayoutEffect","maxHeight","Math","max","documentElement","clientHeight","innerHeight","rect","current","getBoundingClientRect","anchorHeight","height","anchorX","x","screenWidth","innerWidth","isUp","top","isDown","isLeft","isRight"],"mappings":";;;;AASO,MAAMA,eAAe,GAAGA,CAC7BC,SAAiC,EACjCC,UAAkC,EAClCC,QAAiB,KACJ;EACb,MAAM,CAACC,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGC,QAAQ,CACtD,
|
|
1
|
+
{"version":3,"file":"useAutoPosition.js","sources":["../../../../src/shared/useAutoPosition.ts"],"sourcesContent":["import { useState, useLayoutEffect, RefObject } from \"react\";\n\nimport { useWindow } from \"./useWindow\";\nimport { useDocument } from \"./useDocument\";\n\nexport type VerticalPosition = \"up\" | \"down\";\nexport type HorizontalPosition = \"left\" | \"right\";\nexport type Position = [VerticalPosition, HorizontalPosition];\n\nexport const useAutoPosition = (\n anchorRef: RefObject<HTMLElement>,\n contentRef: RefObject<HTMLElement>,\n isActive: boolean\n): Position => {\n const [verticalPosition, setVerticalPosition] = useState(\n \"down\" as VerticalPosition\n );\n const [horizontalPosition, setHorizontalPosition] = useState(\n \"left\" as HorizontalPosition\n );\n const document = useDocument();\n const window = useWindow();\n\n useLayoutEffect(() => {\n if (!contentRef) return;\n\n if (isActive) {\n const maxHeight = Math.max(\n document.documentElement.clientHeight || 0,\n window.innerHeight || 0\n );\n\n const rect: DOMRect = contentRef.current.getBoundingClientRect();\n const anchorHeight = anchorRef.current.getBoundingClientRect().height;\n const anchorX = anchorRef.current.getBoundingClientRect().x;\n const screenWidth = window.innerWidth;\n\n const isUp = rect.top + rect.height > maxHeight;\n const isDown = rect.top - anchorHeight < rect.height;\n const isLeft = anchorX > screenWidth / 2;\n const isRight = anchorX < screenWidth / 2;\n\n if (isUp) {\n setVerticalPosition(\"up\");\n } else if (isDown) {\n setVerticalPosition(\"down\");\n }\n\n if (isLeft) {\n setHorizontalPosition(\"left\");\n } else if (isRight) {\n setHorizontalPosition(\"right\");\n }\n } else {\n setVerticalPosition(\"down\");\n setHorizontalPosition(\"left\");\n }\n }, [\n anchorRef,\n contentRef,\n document.documentElement.clientHeight,\n isActive,\n window.innerHeight,\n window.innerWidth,\n ]);\n\n return [verticalPosition, horizontalPosition];\n};\n"],"names":["useAutoPosition","anchorRef","contentRef","isActive","verticalPosition","setVerticalPosition","useState","horizontalPosition","setHorizontalPosition","document","useDocument","window","useWindow","useLayoutEffect","maxHeight","Math","max","documentElement","clientHeight","innerHeight","rect","current","getBoundingClientRect","anchorHeight","height","anchorX","x","screenWidth","innerWidth","isUp","top","isDown","isLeft","isRight"],"mappings":";;;;AASO,MAAMA,eAAe,GAAGA,CAC7BC,SAAiC,EACjCC,UAAkC,EAClCC,QAAiB,KACJ;EACb,MAAM,CAACC,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGC,QAAQ,CACtD,MACF,CAAC,CAAA;EACD,MAAM,CAACC,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGF,QAAQ,CAC1D,MACF,CAAC,CAAA;AACD,EAAA,MAAMG,QAAQ,GAAGC,WAAW,EAAE,CAAA;AAC9B,EAAA,MAAMC,MAAM,GAAGC,SAAS,EAAE,CAAA;AAE1BC,EAAAA,eAAe,CAAC,MAAM;IACpB,IAAI,CAACX,UAAU,EAAE,OAAA;AAEjB,IAAA,IAAIC,QAAQ,EAAE;AACZ,MAAA,MAAMW,SAAS,GAAGC,IAAI,CAACC,GAAG,CACxBP,QAAQ,CAACQ,eAAe,CAACC,YAAY,IAAI,CAAC,EAC1CP,MAAM,CAACQ,WAAW,IAAI,CACxB,CAAC,CAAA;MAED,MAAMC,IAAa,GAAGlB,UAAU,CAACmB,OAAO,CAACC,qBAAqB,EAAE,CAAA;MAChE,MAAMC,YAAY,GAAGtB,SAAS,CAACoB,OAAO,CAACC,qBAAqB,EAAE,CAACE,MAAM,CAAA;MACrE,MAAMC,OAAO,GAAGxB,SAAS,CAACoB,OAAO,CAACC,qBAAqB,EAAE,CAACI,CAAC,CAAA;AAC3D,MAAA,MAAMC,WAAW,GAAGhB,MAAM,CAACiB,UAAU,CAAA;MAErC,MAAMC,IAAI,GAAGT,IAAI,CAACU,GAAG,GAAGV,IAAI,CAACI,MAAM,GAAGV,SAAS,CAAA;MAC/C,MAAMiB,MAAM,GAAGX,IAAI,CAACU,GAAG,GAAGP,YAAY,GAAGH,IAAI,CAACI,MAAM,CAAA;AACpD,MAAA,MAAMQ,MAAM,GAAGP,OAAO,GAAGE,WAAW,GAAG,CAAC,CAAA;AACxC,MAAA,MAAMM,OAAO,GAAGR,OAAO,GAAGE,WAAW,GAAG,CAAC,CAAA;AAEzC,MAAA,IAAIE,IAAI,EAAE;QACRxB,mBAAmB,CAAC,IAAI,CAAC,CAAA;OAC1B,MAAM,IAAI0B,MAAM,EAAE;QACjB1B,mBAAmB,CAAC,MAAM,CAAC,CAAA;AAC7B,OAAA;AAEA,MAAA,IAAI2B,MAAM,EAAE;QACVxB,qBAAqB,CAAC,MAAM,CAAC,CAAA;OAC9B,MAAM,IAAIyB,OAAO,EAAE;QAClBzB,qBAAqB,CAAC,OAAO,CAAC,CAAA;AAChC,OAAA;AACF,KAAC,MAAM;MACLH,mBAAmB,CAAC,MAAM,CAAC,CAAA;MAC3BG,qBAAqB,CAAC,MAAM,CAAC,CAAA;AAC/B,KAAA;GACD,EAAE,CACDP,SAAS,EACTC,UAAU,EACVO,QAAQ,CAACQ,eAAe,CAACC,YAAY,EACrCf,QAAQ,EACRQ,MAAM,CAACQ,WAAW,EAClBR,MAAM,CAACiB,UAAU,CAClB,CAAC,CAAA;AAEF,EAAA,OAAO,CAACxB,gBAAgB,EAAEG,kBAAkB,CAAC,CAAA;AAC/C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useKeyboard.js","sources":["../../../../src/shared/useKeyboard.ts"],"sourcesContent":["import { useEffect, RefObject } from \"react\";\nimport { useDocument } from \"./useDocument\";\n\n/**\n * useKeyboard handles activation of keyboard hotkeys on a given element.\n * @param {Record<string, (e: KeyboardEvent) => {}} config - A map of keyboardEvent code to function.\n * @param {RefObject} ref - The element which the keyboard config has to apply on.\n * @param {boolean} isActive - A flag to determine when the keyboard config has to be applied.\n *\n * Example:\n * useKeyboard({\n * Escape: closeMenu,\n * ArrowUp: () => { doSomething() },\n * KeyB: () => { console.log(\"bagi\") },\n * }, menuRef, menuOpen)\n *\n * This mean that these keyboard shortcuts will be applied on menuRef when the menu is opened.\n */\n\nexport function useKeyboard(\n config: Record<string, (e: KeyboardEvent) => void | boolean>,\n ref: RefObject<any>,\n isActive: boolean\n): void {\n const document = useDocument();\n const handleKeyboard = (event: KeyboardEvent) => {\n if (!isActive) return;\n\n if (\n document.activeElement !== ref.current &&\n !ref.current.contains(document.activeElement)\n )\n return;\n\n const targetConfigKey = Object.keys(config).find((targetKeys: string) =>\n targetKeys.split(\" \").includes(event.code)\n );\n if (!targetConfigKey) return;\n\n event.preventDefault();\n const res = config[targetConfigKey](event);\n if (res === false) {\n event.stopPropagation();\n }\n };\n\n useEffect(() => {\n document.addEventListener(\"keydown\", handleKeyboard);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeyboard);\n };\n });\n}\n"],"names":["useKeyboard","config","ref","isActive","document","useDocument","handleKeyboard","event","activeElement","current","contains","targetConfigKey","Object","keys","find","targetKeys","split","includes","code","preventDefault","res","stopPropagation","useEffect","addEventListener","removeEventListener"],"mappings":";;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,SAASA,WAAWA,CACzBC,MAA4D,EAC5DC,GAAmB,EACnBC,QAAiB,EACX;
|
|
1
|
+
{"version":3,"file":"useKeyboard.js","sources":["../../../../src/shared/useKeyboard.ts"],"sourcesContent":["import { useEffect, RefObject } from \"react\";\nimport { useDocument } from \"./useDocument\";\n\n/**\n * useKeyboard handles activation of keyboard hotkeys on a given element.\n * @param {Record<string, (e: KeyboardEvent) => {}} config - A map of keyboardEvent code to function.\n * @param {RefObject} ref - The element which the keyboard config has to apply on.\n * @param {boolean} isActive - A flag to determine when the keyboard config has to be applied.\n *\n * Example:\n * useKeyboard({\n * Escape: closeMenu,\n * ArrowUp: () => { doSomething() },\n * KeyB: () => { console.log(\"bagi\") },\n * }, menuRef, menuOpen)\n *\n * This mean that these keyboard shortcuts will be applied on menuRef when the menu is opened.\n */\n\nexport function useKeyboard(\n config: Record<string, (e: KeyboardEvent) => void | boolean>,\n ref: RefObject<any>,\n isActive: boolean\n): void {\n const document = useDocument();\n const handleKeyboard = (event: KeyboardEvent) => {\n if (!isActive) return;\n\n if (\n document.activeElement !== ref.current &&\n !ref.current.contains(document.activeElement)\n )\n return;\n\n const targetConfigKey = Object.keys(config).find((targetKeys: string) =>\n targetKeys.split(\" \").includes(event.code)\n );\n if (!targetConfigKey) return;\n\n event.preventDefault();\n const res = config[targetConfigKey](event);\n if (res === false) {\n event.stopPropagation();\n }\n };\n\n useEffect(() => {\n document.addEventListener(\"keydown\", handleKeyboard);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeyboard);\n };\n });\n}\n"],"names":["useKeyboard","config","ref","isActive","document","useDocument","handleKeyboard","event","activeElement","current","contains","targetConfigKey","Object","keys","find","targetKeys","split","includes","code","preventDefault","res","stopPropagation","useEffect","addEventListener","removeEventListener"],"mappings":";;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,SAASA,WAAWA,CACzBC,MAA4D,EAC5DC,GAAmB,EACnBC,QAAiB,EACX;AACN,EAAA,MAAMC,QAAQ,GAAGC,WAAW,EAAE,CAAA;EAC9B,MAAMC,cAAc,GAAIC,KAAoB,IAAK;IAC/C,IAAI,CAACJ,QAAQ,EAAE,OAAA;AAEf,IAAA,IACEC,QAAQ,CAACI,aAAa,KAAKN,GAAG,CAACO,OAAO,IACtC,CAACP,GAAG,CAACO,OAAO,CAACC,QAAQ,CAACN,QAAQ,CAACI,aAAa,CAAC,EAE7C,OAAA;IAEF,MAAMG,eAAe,GAAGC,MAAM,CAACC,IAAI,CAACZ,MAAM,CAAC,CAACa,IAAI,CAAEC,UAAkB,IAClEA,UAAU,CAACC,KAAK,CAAC,GAAG,CAAC,CAACC,QAAQ,CAACV,KAAK,CAACW,IAAI,CAC3C,CAAC,CAAA;IACD,IAAI,CAACP,eAAe,EAAE,OAAA;IAEtBJ,KAAK,CAACY,cAAc,EAAE,CAAA;IACtB,MAAMC,GAAG,GAAGnB,MAAM,CAACU,eAAe,CAAC,CAACJ,KAAK,CAAC,CAAA;IAC1C,IAAIa,GAAG,KAAK,KAAK,EAAE;MACjBb,KAAK,CAACc,eAAe,EAAE,CAAA;AACzB,KAAA;GACD,CAAA;AAEDC,EAAAA,SAAS,CAAC,MAAM;AACdlB,IAAAA,QAAQ,CAACmB,gBAAgB,CAAC,SAAS,EAAEjB,cAAc,CAAC,CAAA;AAEpD,IAAA,OAAO,MAAM;AACXF,MAAAA,QAAQ,CAACoB,mBAAmB,CAAC,SAAS,EAAElB,cAAc,CAAC,CAAA;KACxD,CAAA;AACH,GAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOnEscapePress.js","sources":["../../../../src/shared/useOnEscapePress.ts"],"sourcesContent":["import { useEffect, useCallback, useMemo } from \"react\";\nimport { useDocument } from \"./useDocument\";\n\ntype KeyboardEventCallback = (event: KeyboardEvent) => void;\n\nconst registry: { [id: number]: KeyboardEventCallback } = {};\n\nconst handleEscape = (event: KeyboardEvent) => {\n if (!event.defaultPrevented) {\n const handlers = Object.values(registry).reverse();\n\n for (let i = 0; i < handlers.length; i += 1) {\n const handler = handlers[i];\n\n handler(event);\n\n if (event.defaultPrevented) break;\n }\n }\n};\n\nconst register = (id: number, handler: KeyboardEventCallback): void => {\n registry[id] = handler;\n};\n\nconst deregister = (id: number) => {\n delete registry[id];\n};\n\n// For auto-incrementing unique identifiers for registered different handlers.\nlet handlerId = 0;\n\nexport const useOnEscapePress = (\n onEscape: (e: KeyboardEvent) => void,\n callbackDependencies: React.DependencyList = [onEscape]\n): void => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const escapeCallback = useCallback(onEscape, callbackDependencies);\n const document = useDocument();\n\n const handler = useCallback<KeyboardEventCallback>(\n (event) => {\n if (event.key === \"Escape\") escapeCallback(event);\n },\n [escapeCallback]\n );\n\n const id = useMemo(() => {\n handlerId += 1;\n return handlerId;\n }, []);\n\n useEffect(() => {\n if (Object.keys(registry).length === 0) {\n document.addEventListener(\"keydown\", handleEscape);\n }\n register(id, handler);\n\n return () => {\n deregister(id);\n if (Object.keys(registry).length === 0) {\n document.removeEventListener(\"keydown\", handleEscape);\n }\n };\n }, [id, handler, document]);\n};\n"],"names":["registry","handleEscape","event","defaultPrevented","handlers","Object","values","reverse","i","length","handler","register","id","deregister","handlerId","useOnEscapePress","onEscape","callbackDependencies","arguments","undefined","escapeCallback","useCallback","document","useDocument","key","useMemo","useEffect","keys","addEventListener","removeEventListener"],"mappings":";;;AAKA,MAAMA,QAAiD,GAAG,EAAE,CAAA;AAE5D,MAAMC,YAAY,GAAIC,KAAoB,IAAK;AAC7C,EAAA,IAAI,CAACA,KAAK,CAACC,gBAAgB,EAAE;IAC3B,MAAMC,QAAQ,GAAGC,MAAM,CAACC,MAAM,CAACN,QAAQ,CAAC,CAACO,OAAO,EAAE,CAAA;AAElD,IAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,QAAQ,CAACK,MAAM,EAAED,CAAC,IAAI,CAAC,EAAE;AAC3C,MAAA,MAAME,OAAO,GAAGN,QAAQ,CAACI,CAAC,CAAC,CAAA;MAE3BE,OAAO,CAACR,KAAK,CAAC,CAAA;MAEd,IAAIA,KAAK,CAACC,gBAAgB,EAAE,MAAA;AAC9B,KAAA;AACF,GAAA;AACF,CAAC,CAAA;AAED,MAAMQ,QAAQ,GAAGA,CAACC,EAAU,EAAEF,OAA8B,KAAW;AACrEV,EAAAA,QAAQ,CAACY,EAAE,CAAC,GAAGF,OAAO,CAAA;AACxB,CAAC,CAAA;AAED,MAAMG,UAAU,GAAID,EAAU,IAAK;EACjC,OAAOZ,QAAQ,CAACY,EAAE,CAAC,CAAA;AACrB,CAAC,CAAA;;AAED;AACA,IAAIE,SAAS,GAAG,CAAC,CAAA;MAEJC,gBAAgB,GAAG,UAC9BC,QAAoC,EAE3B;AAAA,EAAA,IADTC,oBAA0C,GAAAC,SAAA,CAAAT,MAAA,GAAAS,CAAAA,IAAAA,SAAA,CAAAC,CAAAA,CAAAA,KAAAA,SAAA,GAAAD,SAAA,CAAG,CAAA,CAAA,GAAA,CAACF,QAAQ,CAAC,CAAA;AAEvD;AACA,EAAA,MAAMI,cAAc,GAAGC,WAAW,CAACL,QAAQ,EAAEC,oBAAoB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"useOnEscapePress.js","sources":["../../../../src/shared/useOnEscapePress.ts"],"sourcesContent":["import { useEffect, useCallback, useMemo } from \"react\";\nimport { useDocument } from \"./useDocument\";\n\ntype KeyboardEventCallback = (event: KeyboardEvent) => void;\n\nconst registry: { [id: number]: KeyboardEventCallback } = {};\n\nconst handleEscape = (event: KeyboardEvent) => {\n if (!event.defaultPrevented) {\n const handlers = Object.values(registry).reverse();\n\n for (let i = 0; i < handlers.length; i += 1) {\n const handler = handlers[i];\n\n handler(event);\n\n if (event.defaultPrevented) break;\n }\n }\n};\n\nconst register = (id: number, handler: KeyboardEventCallback): void => {\n registry[id] = handler;\n};\n\nconst deregister = (id: number) => {\n delete registry[id];\n};\n\n// For auto-incrementing unique identifiers for registered different handlers.\nlet handlerId = 0;\n\nexport const useOnEscapePress = (\n onEscape: (e: KeyboardEvent) => void,\n callbackDependencies: React.DependencyList = [onEscape]\n): void => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const escapeCallback = useCallback(onEscape, callbackDependencies);\n const document = useDocument();\n\n const handler = useCallback<KeyboardEventCallback>(\n (event) => {\n if (event.key === \"Escape\") escapeCallback(event);\n },\n [escapeCallback]\n );\n\n const id = useMemo(() => {\n handlerId += 1;\n return handlerId;\n }, []);\n\n useEffect(() => {\n if (Object.keys(registry).length === 0) {\n document.addEventListener(\"keydown\", handleEscape);\n }\n register(id, handler);\n\n return () => {\n deregister(id);\n if (Object.keys(registry).length === 0) {\n document.removeEventListener(\"keydown\", handleEscape);\n }\n };\n }, [id, handler, document]);\n};\n"],"names":["registry","handleEscape","event","defaultPrevented","handlers","Object","values","reverse","i","length","handler","register","id","deregister","handlerId","useOnEscapePress","onEscape","callbackDependencies","arguments","undefined","escapeCallback","useCallback","document","useDocument","key","useMemo","useEffect","keys","addEventListener","removeEventListener"],"mappings":";;;AAKA,MAAMA,QAAiD,GAAG,EAAE,CAAA;AAE5D,MAAMC,YAAY,GAAIC,KAAoB,IAAK;AAC7C,EAAA,IAAI,CAACA,KAAK,CAACC,gBAAgB,EAAE;IAC3B,MAAMC,QAAQ,GAAGC,MAAM,CAACC,MAAM,CAACN,QAAQ,CAAC,CAACO,OAAO,EAAE,CAAA;AAElD,IAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,QAAQ,CAACK,MAAM,EAAED,CAAC,IAAI,CAAC,EAAE;AAC3C,MAAA,MAAME,OAAO,GAAGN,QAAQ,CAACI,CAAC,CAAC,CAAA;MAE3BE,OAAO,CAACR,KAAK,CAAC,CAAA;MAEd,IAAIA,KAAK,CAACC,gBAAgB,EAAE,MAAA;AAC9B,KAAA;AACF,GAAA;AACF,CAAC,CAAA;AAED,MAAMQ,QAAQ,GAAGA,CAACC,EAAU,EAAEF,OAA8B,KAAW;AACrEV,EAAAA,QAAQ,CAACY,EAAE,CAAC,GAAGF,OAAO,CAAA;AACxB,CAAC,CAAA;AAED,MAAMG,UAAU,GAAID,EAAU,IAAK;EACjC,OAAOZ,QAAQ,CAACY,EAAE,CAAC,CAAA;AACrB,CAAC,CAAA;;AAED;AACA,IAAIE,SAAS,GAAG,CAAC,CAAA;MAEJC,gBAAgB,GAAG,UAC9BC,QAAoC,EAE3B;AAAA,EAAA,IADTC,oBAA0C,GAAAC,SAAA,CAAAT,MAAA,GAAAS,CAAAA,IAAAA,SAAA,CAAAC,CAAAA,CAAAA,KAAAA,SAAA,GAAAD,SAAA,CAAG,CAAA,CAAA,GAAA,CAACF,QAAQ,CAAC,CAAA;AAEvD;AACA,EAAA,MAAMI,cAAc,GAAGC,WAAW,CAACL,QAAQ,EAAEC,oBAAoB,CAAC,CAAA;AAClE,EAAA,MAAMK,QAAQ,GAAGC,WAAW,EAAE,CAAA;AAE9B,EAAA,MAAMb,OAAO,GAAGW,WAAW,CACxBnB,KAAK,IAAK;IACT,IAAIA,KAAK,CAACsB,GAAG,KAAK,QAAQ,EAAEJ,cAAc,CAAClB,KAAK,CAAC,CAAA;AACnD,GAAC,EACD,CAACkB,cAAc,CACjB,CAAC,CAAA;AAED,EAAA,MAAMR,EAAE,GAAGa,OAAO,CAAC,MAAM;AACvBX,IAAAA,SAAS,IAAI,CAAC,CAAA;AACd,IAAA,OAAOA,SAAS,CAAA;GACjB,EAAE,EAAE,CAAC,CAAA;AAENY,EAAAA,SAAS,CAAC,MAAM;IACd,IAAIrB,MAAM,CAACsB,IAAI,CAAC3B,QAAQ,CAAC,CAACS,MAAM,KAAK,CAAC,EAAE;AACtCa,MAAAA,QAAQ,CAACM,gBAAgB,CAAC,SAAS,EAAE3B,YAAY,CAAC,CAAA;AACpD,KAAA;AACAU,IAAAA,QAAQ,CAACC,EAAE,EAAEF,OAAO,CAAC,CAAA;AAErB,IAAA,OAAO,MAAM;MACXG,UAAU,CAACD,EAAE,CAAC,CAAA;MACd,IAAIP,MAAM,CAACsB,IAAI,CAAC3B,QAAQ,CAAC,CAACS,MAAM,KAAK,CAAC,EAAE;AACtCa,QAAAA,QAAQ,CAACO,mBAAmB,CAAC,SAAS,EAAE5B,YAAY,CAAC,CAAA;AACvD,OAAA;KACD,CAAA;GACF,EAAE,CAACW,EAAE,EAAEF,OAAO,EAAEY,QAAQ,CAAC,CAAC,CAAA;AAC7B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOutsideClick.js","sources":["../../../../src/shared/useOutsideClick.ts"],"sourcesContent":["import { useEffect, useCallback, RefObject } from \"react\";\n\nimport { useWindow } from \"./useWindow\";\n\n/**\n * useOutsideClick handles outside click of a given element.\n * @param {RefObject} ref - Reference to a DOM element.\n * @param {e: Event) => void} handler - Function invoked when a click is triggered outside the referenced element.\n * @param {boolean} isActive - A flag to determine when the outside click event needs to be applied.\n *\n * Example: useOutsideClick(menuRef, closeMenu, menuIsOpen)\n * Means that when a menu is opened, clicking outside of the menu will close the mneu.\n */\n\nexport const useOutsideClick = (\n ref: RefObject<any>,\n handler: (e: Event) => void,\n isActive: boolean\n): void => {\n const window = useWindow();\n\n const outsideClickEvent = useCallback(\n (e: Event) => {\n if (ref && ref.current && !ref.current.contains(e.target)) {\n handler(e);\n }\n },\n [handler, ref]\n );\n\n useEffect(() => {\n if (isActive) {\n window.addEventListener(\"click\", outsideClickEvent);\n }\n\n return () => {\n window.removeEventListener(\"click\", outsideClickEvent);\n };\n }, [isActive, window, outsideClickEvent]);\n};\n"],"names":["useOutsideClick","ref","handler","isActive","window","useWindow","outsideClickEvent","useCallback","e","current","contains","target","useEffect","addEventListener","removeEventListener"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,eAAe,GAAGA,CAC7BC,GAAmB,EACnBC,OAA2B,EAC3BC,QAAiB,KACR;
|
|
1
|
+
{"version":3,"file":"useOutsideClick.js","sources":["../../../../src/shared/useOutsideClick.ts"],"sourcesContent":["import { useEffect, useCallback, RefObject } from \"react\";\n\nimport { useWindow } from \"./useWindow\";\n\n/**\n * useOutsideClick handles outside click of a given element.\n * @param {RefObject} ref - Reference to a DOM element.\n * @param {e: Event) => void} handler - Function invoked when a click is triggered outside the referenced element.\n * @param {boolean} isActive - A flag to determine when the outside click event needs to be applied.\n *\n * Example: useOutsideClick(menuRef, closeMenu, menuIsOpen)\n * Means that when a menu is opened, clicking outside of the menu will close the mneu.\n */\n\nexport const useOutsideClick = (\n ref: RefObject<any>,\n handler: (e: Event) => void,\n isActive: boolean\n): void => {\n const window = useWindow();\n\n const outsideClickEvent = useCallback(\n (e: Event) => {\n if (ref && ref.current && !ref.current.contains(e.target)) {\n handler(e);\n }\n },\n [handler, ref]\n );\n\n useEffect(() => {\n if (isActive) {\n window.addEventListener(\"click\", outsideClickEvent);\n }\n\n return () => {\n window.removeEventListener(\"click\", outsideClickEvent);\n };\n }, [isActive, window, outsideClickEvent]);\n};\n"],"names":["useOutsideClick","ref","handler","isActive","window","useWindow","outsideClickEvent","useCallback","e","current","contains","target","useEffect","addEventListener","removeEventListener"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,eAAe,GAAGA,CAC7BC,GAAmB,EACnBC,OAA2B,EAC3BC,QAAiB,KACR;AACT,EAAA,MAAMC,MAAM,GAAGC,SAAS,EAAE,CAAA;AAE1B,EAAA,MAAMC,iBAAiB,GAAGC,WAAW,CAClCC,CAAQ,IAAK;AACZ,IAAA,IAAIP,GAAG,IAAIA,GAAG,CAACQ,OAAO,IAAI,CAACR,GAAG,CAACQ,OAAO,CAACC,QAAQ,CAACF,CAAC,CAACG,MAAM,CAAC,EAAE;MACzDT,OAAO,CAACM,CAAC,CAAC,CAAA;AACZ,KAAA;AACF,GAAC,EACD,CAACN,OAAO,EAAED,GAAG,CACf,CAAC,CAAA;AAEDW,EAAAA,SAAS,CAAC,MAAM;AACd,IAAA,IAAIT,QAAQ,EAAE;AACZC,MAAAA,MAAM,CAACS,gBAAgB,CAAC,OAAO,EAAEP,iBAAiB,CAAC,CAAA;AACrD,KAAA;AAEA,IAAA,OAAO,MAAM;AACXF,MAAAA,MAAM,CAACU,mBAAmB,CAAC,OAAO,EAAER,iBAAiB,CAAC,CAAA;KACvD,CAAA;GACF,EAAE,CAACH,QAAQ,EAAEC,MAAM,EAAEE,iBAAiB,CAAC,CAAC,CAAA;AAC3C;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amboss/design-system",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "the design system for AMBOSS products",
|
|
5
5
|
"author": "Bagrat Gobedashvili",
|
|
6
6
|
"license": "ISC",
|
|
@@ -30,12 +30,6 @@
|
|
|
30
30
|
"eslint --fix"
|
|
31
31
|
]
|
|
32
32
|
},
|
|
33
|
-
"husky": {
|
|
34
|
-
"hooks": {
|
|
35
|
-
"pre-commit": "npx lint-staged",
|
|
36
|
-
"pre-push": "npm run test"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
33
|
"auto": {
|
|
40
34
|
"plugins": [
|
|
41
35
|
"npm",
|
|
@@ -71,14 +65,15 @@
|
|
|
71
65
|
"tokens": "node style-dictionary/style-dictionary.build.js",
|
|
72
66
|
"tokens:watch": "chokidar \"tokens/**/*.json\" -c \"npm run tokens\"",
|
|
73
67
|
"tokens:prettier": "prettier --write \"build-tokens/*.(t|j)s*\"",
|
|
74
|
-
"chromatic": "npx chromatic --project-token ${CHROMATIC_TOKEN} --exit-zero-on-changes",
|
|
75
|
-
"chromatic:ci": "npx chromatic --project-token ${CHROMATIC_TOKEN} --skip 'dependabot/**' --exit-zero-on-changes",
|
|
76
|
-
"chromatic:master": "npx chromatic --project-token ${CHROMATIC_TOKEN} --auto-accept-changes",
|
|
68
|
+
"chromatic": "npx chromatic --project-token ${CHROMATIC_TOKEN} --exit-zero-on-changes --only-changed",
|
|
69
|
+
"chromatic:ci": "npx chromatic --project-token ${CHROMATIC_TOKEN} --skip 'dependabot/**' --exit-zero-on-changes --only-changed",
|
|
70
|
+
"chromatic:master": "npx chromatic --project-token ${CHROMATIC_TOKEN} --auto-accept-changes --only-changed",
|
|
77
71
|
"lint": "npm run lint:eslint && npm run lint:prettier",
|
|
78
72
|
"lint:eslint": "eslint -c .eslintrc --fix src .storybook test-utils",
|
|
79
73
|
"lint:prettier": "prettier --write \"{src,tokens,.storybook,test-utils}/**/*.(t|j)s*\"",
|
|
80
74
|
"component": "DS_ROOT=/src/components DS_COMP_FOLDER=/components node scripts/createComponent/createComponent.js",
|
|
81
|
-
"link-ds": "./scripts/link-ds.sh"
|
|
75
|
+
"link-ds": "./scripts/link-ds.sh",
|
|
76
|
+
"prepare": "husky install"
|
|
82
77
|
},
|
|
83
78
|
"repository": {
|
|
84
79
|
"type": "git",
|
|
@@ -164,7 +159,7 @@
|
|
|
164
159
|
"feather-icons": "^4.28.0",
|
|
165
160
|
"html-webpack-plugin": "^5.5.0",
|
|
166
161
|
"http-server": "^14.1.1",
|
|
167
|
-
"husky": "^
|
|
162
|
+
"husky": "^8.0.3",
|
|
168
163
|
"identity-obj-proxy": "^3.0.0",
|
|
169
164
|
"inquirer": "^8.1.2",
|
|
170
165
|
"jest": "^26.6.1",
|