@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @vygruppen/spor-react@7.1.1 build
2
+ > @vygruppen/spor-react@7.2.0 build
3
3
  > tsup src/index.tsx --dts --treeshake --format cjs,esm
4
4
 
5
5
  CLI Building entry: src/index.tsx
@@ -8,15 +8,15 @@
8
8
  CLI Target: node16
9
9
  CJS Build start
10
10
  ESM Build start
11
- "Collapse" is imported from external module "@chakra-ui/react" but never used in "dist/chunk-RPCU5IOH.mjs".
11
+ "Collapse" is imported from external module "@chakra-ui/react" but never used in "dist/chunk-D64WYI7V.mjs".
12
12
  DTS Build start
13
13
  "Collapse" is imported from external module "@chakra-ui/react" but never used in "dist/index.js".
14
14
  ESM dist/index.mjs 2.16 KB
15
- ESM dist/CountryCodeSelect-HHSDOINA.mjs 1.19 KB
16
- ESM dist/chunk-RPCU5IOH.mjs 386.90 KB
17
- ESM ⚡️ Build success in 2245ms
18
- CJS dist/index.js 494.17 KB
19
- CJS ⚡️ Build success in 2253ms
20
- DTS ⚡️ Build success in 10730ms
21
- DTS dist/index.d.ts 264.83 KB
22
- DTS dist/index.d.mts 264.83 KB
15
+ ESM dist/CountryCodeSelect-QICAOALV.mjs 1.19 KB
16
+ ESM dist/chunk-D64WYI7V.mjs 387.61 KB
17
+ ESM ⚡️ Build success in 2217ms
18
+ CJS dist/index.js 495.01 KB
19
+ CJS ⚡️ Build success in 2217ms
20
+ DTS ⚡️ Build success in 11050ms
21
+ DTS dist/index.d.ts 265.56 KB
22
+ DTS dist/index.d.mts 265.56 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @vygruppen/spor-react
2
2
 
3
+ ## 7.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 672d254: Heading: New prop "autoId" lets you autogenerate an ID based on the content
8
+ slugify: New export that lets you slugify a string
9
+
3
10
  ## 7.1.1
4
11
 
5
12
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { createTexts, useTranslation, InfoSelect, Item } from './chunk-RPCU5IOH.mjs';
1
+ import { createTexts, useTranslation, InfoSelect, Item } from './chunk-D64WYI7V.mjs';
2
2
  import React from 'react';
3
3
  import { getSupportedCallingCodes } from 'awesome-phonenumber';
4
4
 
@@ -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
- return /* @__PURE__ */ React69__default.createElement(Text, { as, textStyle: variant, ...props });
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-HHSDOINA.mjs'));
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
- 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, theme, useSize, useToast, useTranslation };
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
- 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, theme, useToast, useTranslation };
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
- 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, theme, useToast, useTranslation };
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
- return /* @__PURE__ */ React69__namespace.default.createElement(react.Text, { as, textStyle: variant, ...props });
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-RPCU5IOH.mjs';
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@vygruppen/spor-react",
3
- "version": "7.1.1",
3
+ "version": "7.2.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -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
- return <Text as={as} textStyle={variant} {...props} />;
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
  };
@@ -1 +1,2 @@
1
1
  export * from "./externals";
2
+ export * from "./slugify";
@@ -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
+ }