@vygruppen/spor-react 7.1.1 → 7.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +7 -0
- package/dist/{CountryCodeSelect-HHSDOINA.mjs → CountryCodeSelect-QICAOALV.mjs} +1 -1
- package/dist/{chunk-RPCU5IOH.mjs → chunk-D64WYI7V.mjs} +20 -3
- package/dist/index.d.mts +22 -2
- package/dist/index.d.ts +22 -2
- package/dist/index.js +25 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/typography/Heading.tsx +17 -1
- package/src/util/index.tsx +1 -0
- package/src/util/slugify.tsx +36 -0
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> @vygruppen/spor-react@7.
|
2
|
+
> @vygruppen/spor-react@7.2.0 build
|
3
3
|
> tsup src/index.tsx --dts --treeshake --format cjs,esm
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: src/index.tsx
|
@@ -8,15 +8,15 @@
|
|
8
8
|
[34mCLI[39m Target: node16
|
9
9
|
[34mCJS[39m Build start
|
10
10
|
[34mESM[39m Build start
|
11
|
-
"Collapse" is imported from external module "@chakra-ui/react" but never used in "dist/chunk-
|
11
|
+
"Collapse" is imported from external module "@chakra-ui/react" but never used in "dist/chunk-D64WYI7V.mjs".
|
12
12
|
[34mDTS[39m Build start
|
13
13
|
"Collapse" is imported from external module "@chakra-ui/react" but never used in "dist/index.js".
|
14
14
|
[32mESM[39m [1mdist/index.mjs [22m[32m2.16 KB[39m
|
15
|
-
[32mESM[39m [1mdist/CountryCodeSelect-
|
16
|
-
[32mESM[39m [1mdist/chunk-
|
17
|
-
[32mESM[39m ⚡️ Build success in
|
18
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
19
|
-
[32mCJS[39m ⚡️ Build success in
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
21
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
22
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
15
|
+
[32mESM[39m [1mdist/CountryCodeSelect-QICAOALV.mjs [22m[32m1.19 KB[39m
|
16
|
+
[32mESM[39m [1mdist/chunk-D64WYI7V.mjs [22m[32m387.61 KB[39m
|
17
|
+
[32mESM[39m ⚡️ Build success in 2217ms
|
18
|
+
[32mCJS[39m [1mdist/index.js [22m[32m495.01 KB[39m
|
19
|
+
[32mCJS[39m ⚡️ Build success in 2217ms
|
20
|
+
[32mDTS[39m ⚡️ Build success in 11050ms
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m265.56 KB[39m
|
22
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m265.56 KB[39m
|
package/CHANGELOG.md
CHANGED
@@ -1585,9 +1585,12 @@ var Code = forwardRef((props, ref) => /* @__PURE__ */ React69__default.createEle
|
|
1585
1585
|
var Heading = ({
|
1586
1586
|
as,
|
1587
1587
|
variant = "xl-display",
|
1588
|
+
autoId = false,
|
1589
|
+
id: externalId,
|
1588
1590
|
...props
|
1589
1591
|
}) => {
|
1590
|
-
|
1592
|
+
const id = externalId ?? (autoId && typeof props.children === "string") ? slugify(props.children) : void 0;
|
1593
|
+
return /* @__PURE__ */ React69__default.createElement(Text, { as, textStyle: variant, id, ...props });
|
1591
1594
|
};
|
1592
1595
|
var Text4 = forwardRef(
|
1593
1596
|
({ variant = "sm", ...props }, ref) => {
|
@@ -3417,7 +3420,7 @@ var texts14 = createTexts({
|
|
3417
3420
|
sv: "Telefonnummer"
|
3418
3421
|
}
|
3419
3422
|
});
|
3420
|
-
var LazyCountryCodeSelect = React69__default.lazy(() => import('./CountryCodeSelect-
|
3423
|
+
var LazyCountryCodeSelect = React69__default.lazy(() => import('./CountryCodeSelect-QICAOALV.mjs'));
|
3421
3424
|
var Radio = forwardRef((props, ref) => {
|
3422
3425
|
return /* @__PURE__ */ React69__default.createElement(Radio$1, { ...props, ref });
|
3423
3426
|
});
|
@@ -13660,4 +13663,18 @@ function useSize(subject) {
|
|
13660
13663
|
return size2;
|
13661
13664
|
}
|
13662
13665
|
|
13663
|
-
|
13666
|
+
// src/util/slugify.tsx
|
13667
|
+
function slugify(text, maxLength = 50) {
|
13668
|
+
if (!text) {
|
13669
|
+
return text;
|
13670
|
+
}
|
13671
|
+
if (Array.isArray(text)) {
|
13672
|
+
text = text.join(" ");
|
13673
|
+
}
|
13674
|
+
if (maxLength < 1) {
|
13675
|
+
throw new Error("The maxLength parameter must be a positive number");
|
13676
|
+
}
|
13677
|
+
return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[\u00C6\u00E6]/g, "ae").replace(/[\u00D8\u00F8]/g, "oe").replace(/[\u00C5\u00E5]/g, "aa").toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "").substring(0, maxLength);
|
13678
|
+
}
|
13679
|
+
|
13680
|
+
export { Accordion, AttachedInputs, Badge, Brand, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, ButtonGroup, Card, CardSelect, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, ColorInlineLoader, ColorSpinner, Combobox, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerContent, Expandable, ExpandableAlert, ExpandableItem, FloatingActionButton, FormControl, FormErrorMessage, FormLabel3 as FormLabel, Heading, IconButton, InfoSelect, InfoTag, Input, InputLeftElement2 as InputLeftElement, InputRightElement2 as InputRightElement, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightSpinner, LineIcon, ListBox, ModalHeader, NativeSelect, NumericStepper, PasswordInput, PhoneNumberInput, PlayPauseButton, PopoverWizardBody, ProgressBar, ProgressIndicator, ProgressLoader, Radio, RadioGroup, SearchInput, SimpleDrawer, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Table, Tabs, Text4 as Text, TextLink, Textarea, TimePicker, TravelTag, VyLogo, WizardPopover, brandTheme, createTexts, fontFaces, slugify, theme, useSize, useToast, useTranslation };
|
package/dist/index.d.mts
CHANGED
@@ -7487,6 +7487,8 @@ type HeadingProps = Omit<HeadingProps$1, "textStyle" | "as"> & {
|
|
7487
7487
|
as: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
7488
7488
|
/** The size and style of the heading. Defaults to xl-display */
|
7489
7489
|
variant?: keyof typeof textStyles;
|
7490
|
+
/** If true, generate an ID based on the children */
|
7491
|
+
autoId?: boolean;
|
7490
7492
|
};
|
7491
7493
|
/**
|
7492
7494
|
* Create your own fancy headings with this component.
|
@@ -7503,8 +7505,15 @@ type HeadingProps = Omit<HeadingProps$1, "textStyle" | "as"> & {
|
|
7503
7505
|
* ```tsx
|
7504
7506
|
* <Heading as="h1" variant="2xl">Look at me!</Heading>
|
7505
7507
|
* ```
|
7508
|
+
*
|
7509
|
+
* If you want to generate an ID based on the children, you can use the `autoId` prop.
|
7510
|
+
* Please note that this only works with string children (not JSX, nor arrays of strings).
|
7511
|
+
*
|
7512
|
+
* ```tsx
|
7513
|
+
* <Heading as="h1" autoId>Page heading</Heading> // Will set id="page-heading"
|
7514
|
+
* ```
|
7506
7515
|
*/
|
7507
|
-
declare const Heading: ({ as, variant, ...props }: HeadingProps) => React__default.JSX.Element;
|
7516
|
+
declare const Heading: ({ as, variant, autoId, id: externalId, ...props }: HeadingProps) => React__default.JSX.Element;
|
7508
7517
|
|
7509
7518
|
type TextProps = Omit<TextProps$1, "textStyle"> & {
|
7510
7519
|
/** The size and style of the text.
|
@@ -7521,4 +7530,15 @@ type TextProps = Omit<TextProps$1, "textStyle"> & {
|
|
7521
7530
|
*/
|
7522
7531
|
declare const Text: _chakra_ui_system_dist_system_types.ComponentWithAs<"p", TextProps>;
|
7523
7532
|
|
7524
|
-
|
7533
|
+
/**
|
7534
|
+
* Makes a slug-version of any string.
|
7535
|
+
*
|
7536
|
+
* By default, the maximum length of the slug is 50 characters. You can override this with the `maxLength` parameter.
|
7537
|
+
*
|
7538
|
+
* ```tsx
|
7539
|
+
* slugify("Hello, world!"); // hello-world
|
7540
|
+
* slugify("Hello, world!", 6); // hello-
|
7541
|
+
**/
|
7542
|
+
declare function slugify(text: string | string[], maxLength?: number): string;
|
7543
|
+
|
7544
|
+
export { Accordion, AccordionProps, AttachedInputs, Badge, BadgeProps, Brand, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, ButtonGroup, ButtonGroupProps, ButtonProps, Card, CardProps, CardSelect, Checkbox, CheckboxGroup, CheckboxGroupProps, CheckboxProps, ChoiceChip, ChoiceChipProps, ClosableAlert, CloseButton, CloseButtonProps, Code, CodeProps, ColorInlineLoader, ColorInlineLoaderProps, ColorSpinner, ColorSpinnerProps, Combobox, ComboboxProps, ContentLoader, ContentLoaderProps, DarkFullScreenLoader, DarkInlineLoader, DarkInlineLoaderProps, DarkSpinner, DarkSpinnerProps, DatePicker, DateRangePicker, Divider, DividerProps, Drawer, DrawerContent, ModalHeader as DrawerHeader, Expandable, ExpandableAlert, ExpandableItem, ExpandableItemProps, FloatingActionButton, FormControl, FormControlProps, FormErrorMessage, FormErrorMessageProps, FormLabel, FormLabelProps, Heading, HeadingProps, IconButton, IconButtonProps, InfoSelect, InfoTag, InfoTagProps, Input, InputElementProps, InputLeftElement, InputProps, InputRightElement, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightInlineLoaderProps, LightSpinner, LightSpinnerProps, LineIcon, LineIconProps, ListBox, ModalHeader, ModalHeaderProps, NativeSelect, NativeSelectProps, NumericStepper, PasswordInput, PasswordInputProps, PhoneNumberInput, PlayPauseButton, PopoverWizardBody, PopoverWizardProps, ProgressBar, ProgressIndicator, ProgressLoader, Radio, RadioGroup, RadioGroupProps, RadioProps, SearchInput, SearchInputProps, SimpleDrawer, SimpleDrawerProps, SimplePopover, Skeleton, SkeletonCircle, SkeletonCircleProps, SkeletonProps, SkeletonText, SkeletonTextProps, SkipButton, SpinnerProps, SporProvider, Stack, StackProps, StaticAlert, Stepper, StepperStep, Switch, SwitchProps, Table, TableProps, Tabs, TabsProps, Text, TextLink, TextProps, Textarea, TextareaProps, TimePicker, ToastOptions, Translations, TravelTag, TravelTagProps, VyLogo, VyLogoProps, WizardPopover, WizardPopoverProps, brandTheme, createTexts, fontFaces, slugify, theme, useToast, useTranslation };
|
package/dist/index.d.ts
CHANGED
@@ -7487,6 +7487,8 @@ type HeadingProps = Omit<HeadingProps$1, "textStyle" | "as"> & {
|
|
7487
7487
|
as: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
7488
7488
|
/** The size and style of the heading. Defaults to xl-display */
|
7489
7489
|
variant?: keyof typeof textStyles;
|
7490
|
+
/** If true, generate an ID based on the children */
|
7491
|
+
autoId?: boolean;
|
7490
7492
|
};
|
7491
7493
|
/**
|
7492
7494
|
* Create your own fancy headings with this component.
|
@@ -7503,8 +7505,15 @@ type HeadingProps = Omit<HeadingProps$1, "textStyle" | "as"> & {
|
|
7503
7505
|
* ```tsx
|
7504
7506
|
* <Heading as="h1" variant="2xl">Look at me!</Heading>
|
7505
7507
|
* ```
|
7508
|
+
*
|
7509
|
+
* If you want to generate an ID based on the children, you can use the `autoId` prop.
|
7510
|
+
* Please note that this only works with string children (not JSX, nor arrays of strings).
|
7511
|
+
*
|
7512
|
+
* ```tsx
|
7513
|
+
* <Heading as="h1" autoId>Page heading</Heading> // Will set id="page-heading"
|
7514
|
+
* ```
|
7506
7515
|
*/
|
7507
|
-
declare const Heading: ({ as, variant, ...props }: HeadingProps) => React__default.JSX.Element;
|
7516
|
+
declare const Heading: ({ as, variant, autoId, id: externalId, ...props }: HeadingProps) => React__default.JSX.Element;
|
7508
7517
|
|
7509
7518
|
type TextProps = Omit<TextProps$1, "textStyle"> & {
|
7510
7519
|
/** The size and style of the text.
|
@@ -7521,4 +7530,15 @@ type TextProps = Omit<TextProps$1, "textStyle"> & {
|
|
7521
7530
|
*/
|
7522
7531
|
declare const Text: _chakra_ui_system_dist_system_types.ComponentWithAs<"p", TextProps>;
|
7523
7532
|
|
7524
|
-
|
7533
|
+
/**
|
7534
|
+
* Makes a slug-version of any string.
|
7535
|
+
*
|
7536
|
+
* By default, the maximum length of the slug is 50 characters. You can override this with the `maxLength` parameter.
|
7537
|
+
*
|
7538
|
+
* ```tsx
|
7539
|
+
* slugify("Hello, world!"); // hello-world
|
7540
|
+
* slugify("Hello, world!", 6); // hello-
|
7541
|
+
**/
|
7542
|
+
declare function slugify(text: string | string[], maxLength?: number): string;
|
7543
|
+
|
7544
|
+
export { Accordion, AccordionProps, AttachedInputs, Badge, BadgeProps, Brand, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, ButtonGroup, ButtonGroupProps, ButtonProps, Card, CardProps, CardSelect, Checkbox, CheckboxGroup, CheckboxGroupProps, CheckboxProps, ChoiceChip, ChoiceChipProps, ClosableAlert, CloseButton, CloseButtonProps, Code, CodeProps, ColorInlineLoader, ColorInlineLoaderProps, ColorSpinner, ColorSpinnerProps, Combobox, ComboboxProps, ContentLoader, ContentLoaderProps, DarkFullScreenLoader, DarkInlineLoader, DarkInlineLoaderProps, DarkSpinner, DarkSpinnerProps, DatePicker, DateRangePicker, Divider, DividerProps, Drawer, DrawerContent, ModalHeader as DrawerHeader, Expandable, ExpandableAlert, ExpandableItem, ExpandableItemProps, FloatingActionButton, FormControl, FormControlProps, FormErrorMessage, FormErrorMessageProps, FormLabel, FormLabelProps, Heading, HeadingProps, IconButton, IconButtonProps, InfoSelect, InfoTag, InfoTagProps, Input, InputElementProps, InputLeftElement, InputProps, InputRightElement, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightInlineLoaderProps, LightSpinner, LightSpinnerProps, LineIcon, LineIconProps, ListBox, ModalHeader, ModalHeaderProps, NativeSelect, NativeSelectProps, NumericStepper, PasswordInput, PasswordInputProps, PhoneNumberInput, PlayPauseButton, PopoverWizardBody, PopoverWizardProps, ProgressBar, ProgressIndicator, ProgressLoader, Radio, RadioGroup, RadioGroupProps, RadioProps, SearchInput, SearchInputProps, SimpleDrawer, SimpleDrawerProps, SimplePopover, Skeleton, SkeletonCircle, SkeletonCircleProps, SkeletonProps, SkeletonText, SkeletonTextProps, SkipButton, SpinnerProps, SporProvider, Stack, StackProps, StaticAlert, Stepper, StepperStep, Switch, SwitchProps, Table, TableProps, Tabs, TabsProps, Text, TextLink, TextProps, Textarea, TextareaProps, TimePicker, ToastOptions, Translations, TravelTag, TravelTagProps, VyLogo, VyLogoProps, WizardPopover, WizardPopoverProps, brandTheme, createTexts, fontFaces, slugify, theme, useToast, useTranslation };
|
package/dist/index.js
CHANGED
@@ -1175,12 +1175,16 @@ var init_Code = __esm({
|
|
1175
1175
|
exports.Heading = void 0;
|
1176
1176
|
var init_Heading = __esm({
|
1177
1177
|
"src/typography/Heading.tsx"() {
|
1178
|
+
init_src();
|
1178
1179
|
exports.Heading = ({
|
1179
1180
|
as,
|
1180
1181
|
variant = "xl-display",
|
1182
|
+
autoId = false,
|
1183
|
+
id: externalId,
|
1181
1184
|
...props
|
1182
1185
|
}) => {
|
1183
|
-
|
1186
|
+
const id = externalId ?? (autoId && typeof props.children === "string") ? slugify(props.children) : void 0;
|
1187
|
+
return /* @__PURE__ */ React69__namespace.default.createElement(react.Text, { as, textStyle: variant, id, ...props });
|
1184
1188
|
};
|
1185
1189
|
}
|
1186
1190
|
});
|
@@ -15504,10 +15508,29 @@ var init_externals = __esm({
|
|
15504
15508
|
}
|
15505
15509
|
});
|
15506
15510
|
|
15511
|
+
// src/util/slugify.tsx
|
15512
|
+
function slugify(text, maxLength = 50) {
|
15513
|
+
if (!text) {
|
15514
|
+
return text;
|
15515
|
+
}
|
15516
|
+
if (Array.isArray(text)) {
|
15517
|
+
text = text.join(" ");
|
15518
|
+
}
|
15519
|
+
if (maxLength < 1) {
|
15520
|
+
throw new Error("The maxLength parameter must be a positive number");
|
15521
|
+
}
|
15522
|
+
return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[\u00C6\u00E6]/g, "ae").replace(/[\u00D8\u00F8]/g, "oe").replace(/[\u00C5\u00E5]/g, "aa").toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "").substring(0, maxLength);
|
15523
|
+
}
|
15524
|
+
var init_slugify = __esm({
|
15525
|
+
"src/util/slugify.tsx"() {
|
15526
|
+
}
|
15527
|
+
});
|
15528
|
+
|
15507
15529
|
// src/util/index.tsx
|
15508
15530
|
var init_util = __esm({
|
15509
15531
|
"src/util/index.tsx"() {
|
15510
15532
|
init_externals();
|
15533
|
+
init_slugify();
|
15511
15534
|
}
|
15512
15535
|
});
|
15513
15536
|
var init_src = __esm({
|
@@ -15867,5 +15890,6 @@ exports.LanguageProvider = LanguageProvider;
|
|
15867
15890
|
exports.ListBox = ListBox;
|
15868
15891
|
exports.NumericStepper = NumericStepper;
|
15869
15892
|
exports.createTexts = createTexts;
|
15893
|
+
exports.slugify = slugify;
|
15870
15894
|
exports.useSize = useSize;
|
15871
15895
|
exports.useTranslation = useTranslation;
|
package/dist/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Badge, Box, Brand, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, ListItem, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, NumericStepper, OrderedList, PasswordInput, PhoneNumberInput, PlayPauseButton, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, PopoverWizardBody, Portal, ProgressBar, ProgressIndicator, ProgressLoader, Radio, RadioGroup, ScaleFade, SearchInput, Section, SimpleDrawer, SimpleGrid, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, Tr, TravelTag, UnorderedList, VStack, VyLogo, WizardPopover, Wrap, WrapItem, brandTheme, createTexts, defineStyleConfig, extendTheme, fontFaces, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, useSize, useTheme, useToast, useToken, useTranslation } from './chunk-
|
1
|
+
export { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, AttachedInputs, Badge, Box, Brand, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, ButtonGroup, Card, CardSelect, Center, Checkbox, CheckboxGroup, ChoiceChip, ClosableAlert, CloseButton, Code, ColorInlineLoader, ColorSpinner, Combobox, Container, ContentLoader, DarkFullScreenLoader, DarkInlineLoader, DarkMode, DarkSpinner, DatePicker, DateRangePicker, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, ModalHeader as DrawerHeader, DrawerOverlay, Expandable, ExpandableAlert, ExpandableItem, Fade, Flex, FloatingActionButton, FormControl, FormErrorMessage, FormHelperText, FormLabel, Grid, GridItem, HStack, Heading, IconButton, Image, Img, InfoSelect, InfoTag, Input, InputGroup, InputLeftElement, InputRightElement, Item, ItemDescription, ItemLabel, JumpButton, Language, LanguageProvider, LightFullScreenLoader, LightInlineLoader, LightMode, LightSpinner, LineIcon, ListBox, ListItem, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, NativeSelect, NumericStepper, OrderedList, PasswordInput, PhoneNumberInput, PlayPauseButton, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, PopoverWizardBody, Portal, ProgressBar, ProgressIndicator, ProgressLoader, Radio, RadioGroup, ScaleFade, SearchInput, Section, SimpleDrawer, SimpleGrid, SimplePopover, Skeleton, SkeletonCircle, SkeletonText, SkipButton, Slide, SlideFade, Spacer, SporProvider, Stack, StaticAlert, Stepper, StepperStep, Switch, Tab, TabList, TabPanel, TabPanels, Table, TableCaption, Tabs, Tbody, Td, Text, TextLink, Textarea, Tfoot, Th, Thead, Time, TimePicker, Tr, TravelTag, UnorderedList, VStack, VyLogo, WizardPopover, Wrap, WrapItem, brandTheme, createTexts, defineStyleConfig, extendTheme, fontFaces, slugify, theme, tokens, useBreakpointValue, useClipboard, useColorMode, useColorModePreference, useColorModeValue, useControllableProp, useDisclosure, useMediaQuery, useMergeRefs, useOutsideClick, usePrefersReducedMotion, useSize, useTheme, useToast, useToken, useTranslation } from './chunk-D64WYI7V.mjs';
|
package/package.json
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { HeadingProps as ChakraHeadingProps, Text } from "@chakra-ui/react";
|
2
2
|
import React from "react";
|
3
|
+
import { slugify } from "..";
|
3
4
|
import type { textStyles } from "../theme/foundations";
|
4
5
|
|
5
6
|
export type HeadingProps = Omit<ChakraHeadingProps, "textStyle" | "as"> & {
|
@@ -7,6 +8,8 @@ export type HeadingProps = Omit<ChakraHeadingProps, "textStyle" | "as"> & {
|
|
7
8
|
as: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
8
9
|
/** The size and style of the heading. Defaults to xl-display */
|
9
10
|
variant?: keyof typeof textStyles;
|
11
|
+
/** If true, generate an ID based on the children */
|
12
|
+
autoId?: boolean;
|
10
13
|
};
|
11
14
|
/**
|
12
15
|
* Create your own fancy headings with this component.
|
@@ -23,11 +26,24 @@ export type HeadingProps = Omit<ChakraHeadingProps, "textStyle" | "as"> & {
|
|
23
26
|
* ```tsx
|
24
27
|
* <Heading as="h1" variant="2xl">Look at me!</Heading>
|
25
28
|
* ```
|
29
|
+
*
|
30
|
+
* If you want to generate an ID based on the children, you can use the `autoId` prop.
|
31
|
+
* Please note that this only works with string children (not JSX, nor arrays of strings).
|
32
|
+
*
|
33
|
+
* ```tsx
|
34
|
+
* <Heading as="h1" autoId>Page heading</Heading> // Will set id="page-heading"
|
35
|
+
* ```
|
26
36
|
*/
|
27
37
|
export const Heading = ({
|
28
38
|
as,
|
29
39
|
variant = "xl-display",
|
40
|
+
autoId = false,
|
41
|
+
id: externalId,
|
30
42
|
...props
|
31
43
|
}: HeadingProps) => {
|
32
|
-
|
44
|
+
const id =
|
45
|
+
externalId ?? (autoId && typeof props.children === "string")
|
46
|
+
? slugify(props.children as string)
|
47
|
+
: undefined;
|
48
|
+
return <Text as={as} textStyle={variant} id={id} {...props} />;
|
33
49
|
};
|
package/src/util/index.tsx
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
/**
|
2
|
+
* Makes a slug-version of any string.
|
3
|
+
*
|
4
|
+
* By default, the maximum length of the slug is 50 characters. You can override this with the `maxLength` parameter.
|
5
|
+
*
|
6
|
+
* ```tsx
|
7
|
+
* slugify("Hello, world!"); // hello-world
|
8
|
+
* slugify("Hello, world!", 6); // hello-
|
9
|
+
**/
|
10
|
+
export function slugify(text: string | string[], maxLength = 50): string {
|
11
|
+
if (!text) {
|
12
|
+
return text;
|
13
|
+
}
|
14
|
+
if (Array.isArray(text)) {
|
15
|
+
text = text.join(" ");
|
16
|
+
}
|
17
|
+
if (maxLength < 1) {
|
18
|
+
throw new Error("The maxLength parameter must be a positive number");
|
19
|
+
}
|
20
|
+
return (
|
21
|
+
text
|
22
|
+
.normalize("NFD") // Normalize to NFD Unicode form
|
23
|
+
.replace(/[\u0300-\u036f]/g, "") // Remove diacritics
|
24
|
+
.replace(/[\u00C6\u00E6]/g, "ae") // Replace Æ, æ
|
25
|
+
.replace(/[\u00D8\u00F8]/g, "oe") // Replace Ø, ø
|
26
|
+
.replace(/[\u00C5\u00E5]/g, "aa") // Replace Å, å
|
27
|
+
// Extend the replacement rules as needed
|
28
|
+
.toLowerCase()
|
29
|
+
.replace(/\s+/g, "-") // Replace spaces with -
|
30
|
+
.replace(/[^\w-]+/g, "") // Remove all non-word chars
|
31
|
+
.replace(/--+/g, "-") // Replace multiple - with single -
|
32
|
+
.replace(/^-+/, "") // Trim - from start of text
|
33
|
+
.replace(/-+$/, "")
|
34
|
+
.substring(0, maxLength)
|
35
|
+
);
|
36
|
+
}
|