@entur/typography 3.0.7 → 3.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/README.md +9 -38
- package/dist/beta/cjs/components/Heading.cjs +39 -29
- package/dist/beta/cjs/components/Heading.cjs.map +1 -1
- package/dist/beta/cjs/components/Label.cjs +22 -0
- package/dist/beta/cjs/components/Label.cjs.map +1 -0
- package/dist/beta/cjs/components/Link.cjs +18 -33
- package/dist/beta/cjs/components/Link.cjs.map +1 -1
- package/dist/beta/cjs/components/ListItem.cjs +34 -25
- package/dist/beta/cjs/components/ListItem.cjs.map +1 -1
- package/dist/beta/cjs/components/NumberedList.cjs +36 -24
- package/dist/beta/cjs/components/NumberedList.cjs.map +1 -1
- package/dist/beta/cjs/components/Text.cjs +40 -28
- package/dist/beta/cjs/components/Text.cjs.map +1 -1
- package/dist/beta/cjs/components/TextContainer.cjs +26 -0
- package/dist/beta/cjs/components/TextContainer.cjs.map +1 -0
- package/dist/beta/cjs/components/UnorderedList.cjs +31 -21
- package/dist/beta/cjs/components/UnorderedList.cjs.map +1 -1
- package/dist/beta/cjs/index.cjs +8 -3
- package/dist/beta/cjs/index.cjs.map +1 -1
- package/dist/beta/cjs/utils/utils.cjs +73 -41
- package/dist/beta/cjs/utils/utils.cjs.map +1 -1
- package/dist/beta/cjs/utils/warnAboutGlobalStyles.cjs +113 -0
- package/dist/beta/cjs/utils/warnAboutGlobalStyles.cjs.map +1 -0
- package/dist/beta/esm/components/Heading.mjs +40 -30
- package/dist/beta/esm/components/Heading.mjs.map +1 -1
- package/dist/beta/esm/components/Label.mjs +22 -0
- package/dist/beta/esm/components/Label.mjs.map +1 -0
- package/dist/beta/esm/components/Link.mjs +20 -35
- package/dist/beta/esm/components/Link.mjs.map +1 -1
- package/dist/beta/esm/components/ListItem.mjs +35 -26
- package/dist/beta/esm/components/ListItem.mjs.map +1 -1
- package/dist/beta/esm/components/NumberedList.mjs +37 -25
- package/dist/beta/esm/components/NumberedList.mjs.map +1 -1
- package/dist/beta/esm/components/Text.mjs +41 -29
- package/dist/beta/esm/components/Text.mjs.map +1 -1
- package/dist/beta/esm/components/TextContainer.mjs +26 -0
- package/dist/beta/esm/components/TextContainer.mjs.map +1 -0
- package/dist/beta/esm/components/UnorderedList.mjs +32 -22
- package/dist/beta/esm/components/UnorderedList.mjs.map +1 -1
- package/dist/beta/esm/index.mjs +8 -3
- package/dist/beta/esm/index.mjs.map +1 -1
- package/dist/beta/esm/utils/utils.mjs +73 -41
- package/dist/beta/esm/utils/utils.mjs.map +1 -1
- package/dist/beta/esm/utils/warnAboutGlobalStyles.mjs +113 -0
- package/dist/beta/esm/utils/warnAboutGlobalStyles.mjs.map +1 -0
- package/dist/beta/styles/index.css +878 -609
- package/dist/beta/types/components/Heading.d.ts +27 -11
- package/dist/beta/types/components/Label.d.ts +22 -0
- package/dist/beta/types/components/Link.d.ts +11 -9
- package/dist/beta/types/components/ListItem.d.ts +13 -7
- package/dist/beta/types/components/NumberedList.d.ts +17 -7
- package/dist/beta/types/components/Text.d.ts +33 -13
- package/dist/beta/types/components/TextContainer.d.ts +25 -0
- package/dist/beta/types/components/UnorderedList.d.ts +13 -7
- package/dist/beta/types/index.d.ts +11 -2
- package/dist/beta/types/tests/styles.test.d.ts +1 -0
- package/dist/beta/types/tests/warnAboutGlobalStyles.test.d.ts +1 -0
- package/dist/beta/types/types.d.ts +16 -5
- package/dist/beta/types/utils/utils.d.ts +15 -4
- package/dist/beta/types/utils/warnAboutGlobalStyles.d.ts +4 -0
- package/dist/styles.css +13 -5
- package/dist/styles.no-base-tokens.css +822 -0
- package/package.json +8 -12
- package/dist/beta/cjs/components/Blockquote.cjs +0 -29
- package/dist/beta/cjs/components/Blockquote.cjs.map +0 -1
- package/dist/beta/esm/components/Blockquote.mjs +0 -29
- package/dist/beta/esm/components/Blockquote.mjs.map +0 -1
- package/dist/beta/types/components/Blockquote.d.ts +0 -12
- package/scripts/migrate-typography.mjs +0 -1462
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.mjs","sources":["../../../../src/beta/components/Link.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport {
|
|
1
|
+
{"version":3,"file":"Link.mjs","sources":["../../../../src/beta/components/Link.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport { TypographySpacingProps } from '../types';\nimport { getSpacingStyle } from '../utils/utils';\n\nimport './text.scss';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport type LinkOwnProps = TypographySpacingProps & {\n /** Ekstra klassenavn */\n className?: string;\n /** Innholdet */\n children?: React.ReactNode;\n};\n\nexport type LinkProps<C extends React.ElementType = typeof defaultElement> =\n PolymorphicComponentProps<C, LinkOwnProps>;\n\nexport type LinkComponent = (<\n C extends React.ElementType = typeof defaultElement,\n>(\n props: LinkProps<C> & { ref?: React.Ref<Element> },\n) => React.ReactElement | null) & { displayName?: string };\n\nconst defaultElement = 'a';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport const Link = React.forwardRef(\n <C extends React.ElementType = typeof defaultElement>(\n { className, spacing, style, children, as, ...rest }: LinkProps<C>,\n ref?: React.Ref<Element>,\n ): JSX.Element => {\n const LinkElement: React.ElementType = as || defaultElement;\n\n return (\n <LinkElement\n ref={ref}\n className={classNames('eds-text--link', className)}\n style={getSpacingStyle(spacing, style)}\n {...rest}\n >\n {children}\n </LinkElement>\n );\n },\n) as LinkComponent;\nLink.displayName = 'Link';\n"],"names":[],"mappings":";;;;;AA2BA,MAAM,iBAAiB;AAKhB,MAAM,OAAO,MAAM;AAAA,EACxB,CACE,EAAE,WAAW,SAAS,OAAO,UAAU,IAAI,GAAG,KAAA,GAC9C,QACgB;AAChB,UAAM,cAAiC,MAAM;AAE7C,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW,WAAW,kBAAkB,SAAS;AAAA,QACjD,OAAO,gBAAgB,SAAS,KAAK;AAAA,QACpC,GAAG;AAAA,QAEH;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AACA,KAAK,cAAc;"}
|
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import classNames from "classnames";
|
|
3
|
-
import {
|
|
4
|
+
import { getSpacingStyle } from "../utils/utils.mjs";
|
|
4
5
|
/* empty css */
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
const defaultElement = "li";
|
|
7
|
+
const ListItem = React.forwardRef(
|
|
8
|
+
({
|
|
9
|
+
title,
|
|
10
|
+
className,
|
|
11
|
+
tone,
|
|
12
|
+
spacing,
|
|
13
|
+
style,
|
|
14
|
+
children,
|
|
15
|
+
as,
|
|
16
|
+
...rest
|
|
17
|
+
}, ref) => {
|
|
18
|
+
const ItemElement = as || defaultElement;
|
|
19
|
+
return /* @__PURE__ */ jsxs(
|
|
20
|
+
ItemElement,
|
|
21
|
+
{
|
|
22
|
+
ref,
|
|
23
|
+
className: classNames(
|
|
24
|
+
"eds-text--list-item",
|
|
25
|
+
tone && `eds-text--tone-${tone}`,
|
|
26
|
+
className
|
|
27
|
+
),
|
|
28
|
+
style: getSpacingStyle(spacing, style),
|
|
29
|
+
...rest,
|
|
30
|
+
children: [
|
|
31
|
+
title && /* @__PURE__ */ jsx("span", { className: "eds-text--list-item__title", children: title }),
|
|
32
|
+
children
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
ListItem.displayName = "ListItem";
|
|
30
39
|
export {
|
|
31
40
|
ListItem
|
|
32
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListItem.mjs","sources":["../../../../src/beta/components/ListItem.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport {
|
|
1
|
+
{"version":3,"file":"ListItem.mjs","sources":["../../../../src/beta/components/ListItem.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport { TypographySpacingProps } from '../types';\nimport { getSpacingStyle } from '../utils/utils';\n\nimport './text.scss';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport type ListItemOwnProps = TypographySpacingProps & {\n /** Ekstra klassenavn */\n className?: string;\n /** Dempet punkt, for eksempel et steg som er fullført. Velger riktig farge i kontrast- og mørk modus. */\n tone?: 'subdued';\n /** Innholdet */\n children?: React.ReactNode;\n /** Tittel */\n title?: React.ReactNode;\n};\n\nexport type ListItemProps<C extends React.ElementType = typeof defaultElement> =\n PolymorphicComponentProps<C, ListItemOwnProps>;\n\nexport type ListItemComponent = (<\n C extends React.ElementType = typeof defaultElement,\n>(\n props: ListItemProps<C> & { ref?: React.Ref<Element> },\n) => React.ReactElement | null) & { displayName?: string };\n\nconst defaultElement = 'li';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport const ListItem = React.forwardRef(\n <C extends React.ElementType = typeof defaultElement>(\n {\n title,\n className,\n tone,\n spacing,\n style,\n children,\n as,\n ...rest\n }: ListItemProps<C>,\n ref?: React.Ref<Element>,\n ): JSX.Element => {\n const ItemElement: React.ElementType = as || defaultElement;\n\n return (\n <ItemElement\n ref={ref}\n className={classNames(\n 'eds-text--list-item',\n tone && `eds-text--tone-${tone}`,\n className,\n )}\n style={getSpacingStyle(spacing, style)}\n {...rest}\n >\n {title && <span className=\"eds-text--list-item__title\">{title}</span>}\n {children}\n </ItemElement>\n );\n },\n) as ListItemComponent;\nListItem.displayName = 'ListItem';\n"],"names":[],"mappings":";;;;;AA+BA,MAAM,iBAAiB;AAKhB,MAAM,WAAW,MAAM;AAAA,EAC5B,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACgB;AAChB,UAAM,cAAiC,MAAM;AAE7C,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA,QAAQ,kBAAkB,IAAI;AAAA,UAC9B;AAAA,QAAA;AAAA,QAEF,OAAO,gBAAgB,SAAS,KAAK;AAAA,QACpC,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA,SAAS,oBAAC,QAAA,EAAK,WAAU,8BAA8B,UAAA,OAAM;AAAA,UAC7D;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AACA,SAAS,cAAc;"}
|
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import classNames from "classnames";
|
|
3
|
-
import {
|
|
4
|
+
import { getSpacingStyle } from "../utils/utils.mjs";
|
|
4
5
|
/* empty css */
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
const defaultElement = "ol";
|
|
7
|
+
const NumberedList = React.forwardRef(
|
|
8
|
+
({
|
|
9
|
+
type = "1",
|
|
10
|
+
variant = "default",
|
|
11
|
+
className,
|
|
12
|
+
tone,
|
|
13
|
+
spacing,
|
|
14
|
+
style,
|
|
15
|
+
children,
|
|
16
|
+
as,
|
|
17
|
+
...rest
|
|
18
|
+
}, ref) => {
|
|
19
|
+
const ListElement = as || defaultElement;
|
|
20
|
+
return /* @__PURE__ */ jsx(
|
|
21
|
+
ListElement,
|
|
22
|
+
{
|
|
23
|
+
ref,
|
|
24
|
+
className: classNames(
|
|
25
|
+
"eds-text--numbered-list",
|
|
26
|
+
`eds-text--numbered-list--type-${type}`,
|
|
27
|
+
{ "eds-text--steps": variant === "steps" },
|
|
28
|
+
tone && `eds-text--tone-${tone}`,
|
|
29
|
+
className
|
|
30
|
+
),
|
|
31
|
+
type,
|
|
32
|
+
role: variant === "steps" ? "list" : void 0,
|
|
33
|
+
style: getSpacingStyle(spacing, style),
|
|
34
|
+
...rest,
|
|
35
|
+
children
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
NumberedList.displayName = "NumberedList";
|
|
29
41
|
export {
|
|
30
42
|
NumberedList
|
|
31
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberedList.mjs","sources":["../../../../src/beta/components/NumberedList.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport {
|
|
1
|
+
{"version":3,"file":"NumberedList.mjs","sources":["../../../../src/beta/components/NumberedList.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport { TypographySpacingProps } from '../types';\nimport { getSpacingStyle } from '../utils/utils';\n\nimport './text.scss';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport type NumberedListOwnProps = TypographySpacingProps & {\n /** Ekstra klassenavn */\n className?: string;\n /** Dempet liste for sekundær informasjon, som hjelpetekst. Velger riktig farge i kontrast- og mørk modus. */\n tone?: 'subdued';\n /** Innholdet */\n children?: React.ReactNode;\n /** List type (1, A, a, I, i) */\n type?: '1' | 'A' | 'a' | 'I' | 'i';\n /** `steps` viser numrene i merker, for steg-for-steg-instruksjoner\n * @default 'default'\n */\n variant?: 'default' | 'steps';\n};\n\nexport type NumberedListProps<\n C extends React.ElementType = typeof defaultElement,\n> = PolymorphicComponentProps<C, NumberedListOwnProps>;\n\nexport type NumberedListComponent = (<\n C extends React.ElementType = typeof defaultElement,\n>(\n props: NumberedListProps<C> & { ref?: React.Ref<Element> },\n) => React.ReactElement | null) & { displayName?: string };\n\nconst defaultElement = 'ol';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport const NumberedList = React.forwardRef(\n <C extends React.ElementType = typeof defaultElement>(\n {\n type = '1',\n variant = 'default',\n className,\n tone,\n spacing,\n style,\n children,\n as,\n ...rest\n }: NumberedListProps<C>,\n ref?: React.Ref<Element>,\n ): JSX.Element => {\n const ListElement: React.ElementType = as || defaultElement;\n\n return (\n <ListElement\n ref={ref}\n className={classNames(\n 'eds-text--numbered-list',\n `eds-text--numbered-list--type-${type}`,\n { 'eds-text--steps': variant === 'steps' },\n tone && `eds-text--tone-${tone}`,\n className,\n )}\n type={type}\n // Safari drops list semantics when the list has no markers\n role={variant === 'steps' ? 'list' : undefined}\n style={getSpacingStyle(spacing, style)}\n {...rest}\n >\n {children}\n </ListElement>\n );\n },\n) as NumberedListComponent;\nNumberedList.displayName = 'NumberedList';\n"],"names":[],"mappings":";;;;;AAoCA,MAAM,iBAAiB;AAKhB,MAAM,eAAe,MAAM;AAAA,EAChC,CACE;AAAA,IACE,OAAO;AAAA,IACP,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACgB;AAChB,UAAM,cAAiC,MAAM;AAE7C,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA,iCAAiC,IAAI;AAAA,UACrC,EAAE,mBAAmB,YAAY,QAAA;AAAA,UACjC,QAAQ,kBAAkB,IAAI;AAAA,UAC9B;AAAA,QAAA;AAAA,QAEF;AAAA,QAEA,MAAM,YAAY,UAAU,SAAS;AAAA,QACrC,OAAO,gBAAgB,SAAS,KAAK;AAAA,QACpC,GAAG;AAAA,QAEH;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AACA,aAAa,cAAc;"}
|
|
@@ -1,35 +1,47 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import classNames from "classnames";
|
|
3
|
-
import {
|
|
4
|
+
import { getDefaultTextVariant, getSpacingStyle, getMaxLinesStyle, getSemanticTypeFromTextVariant } from "../utils/utils.mjs";
|
|
4
5
|
/* empty css */
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
6
|
+
const Text = React.forwardRef(
|
|
7
|
+
({
|
|
8
|
+
children,
|
|
9
|
+
as,
|
|
10
|
+
size,
|
|
11
|
+
variant,
|
|
12
|
+
weight,
|
|
13
|
+
tone,
|
|
14
|
+
spacing,
|
|
15
|
+
style,
|
|
16
|
+
trim,
|
|
17
|
+
maxLines,
|
|
18
|
+
className,
|
|
19
|
+
...rest
|
|
20
|
+
}, ref) => {
|
|
21
|
+
const BodyElement = as || getSemanticTypeFromTextVariant(variant);
|
|
22
|
+
const usedVariant = variant ?? getDefaultTextVariant(BodyElement);
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
BodyElement,
|
|
25
|
+
{
|
|
26
|
+
ref,
|
|
27
|
+
className: classNames(
|
|
28
|
+
"eds-text",
|
|
29
|
+
`eds-text--${usedVariant}`,
|
|
30
|
+
size && `eds-text--${size}`,
|
|
31
|
+
weight && `eds-text--weight-${weight}`,
|
|
32
|
+
tone && `eds-text--tone-${tone}`,
|
|
33
|
+
trim && "eds-text--trim",
|
|
34
|
+
maxLines && "eds-text--max-lines",
|
|
35
|
+
className
|
|
36
|
+
),
|
|
37
|
+
style: getSpacingStyle(spacing, getMaxLinesStyle(maxLines, style)),
|
|
38
|
+
...rest,
|
|
39
|
+
children
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
Text.displayName = "Text";
|
|
33
45
|
export {
|
|
34
46
|
Text
|
|
35
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.mjs","sources":["../../../../src/beta/components/Text.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { PolymorphicComponentProps } from '@entur/utils';\n\nimport {\n getSemanticTypeFromTextVariant,\n
|
|
1
|
+
{"version":3,"file":"Text.mjs","sources":["../../../../src/beta/components/Text.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { PolymorphicComponentProps } from '@entur/utils';\n\nimport {\n getDefaultTextVariant,\n getSemanticTypeFromTextVariant,\n getMaxLinesStyle,\n getSpacingStyle,\n} from '../utils/utils';\n\nimport { TypographySpacingProps } from '../types';\n\nimport './text.scss';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport type TextOwnProps = TypographySpacingProps & {\n /** Visuell tekststørrelse (typografi-token) */\n size?: 'xs' | 's' | 'm' | 'lg' | 'xl';\n /** Fontvekt: `medium` (500) eller `bold` (600) */\n weight?: 'medium' | 'bold';\n /** Dempet tekst for sekundær informasjon, som metadata og hjelpetekst. Velger riktig farge i kontrast- og mørk modus. */\n tone?: 'subdued';\n /** Variant (kan brukes til spesielle typer tekst som for eksempel caption).\n * Uten variant blir teksten `paragraph` når den står for seg selv (`p`, `div`, `li` …), og arver\n * størrelse, farge og vekt når den står inne i annen tekst (`span`, `strong`, en komponent …). */\n variant?:\n | 'leading'\n | 'quote'\n | 'paragraph'\n | 'subparagraph'\n | 'caption'\n | 'label'\n | 'sublabel'\n | 'overline'\n | 'emphasized'\n | 'code'\n | 'preformatted';\n /** Innhold */\n children?: React.ReactNode;\n /** Fjerner luften over versalhøyden og under grunnlinjen, så teksten flukter med elementer ved siden av. Har ingen effekt i nettlesere uten støtte for `text-box`. */\n trim?: boolean;\n /** Kutter teksten etter så mange linjer og avslutter med «…». Hele teksten må kunne leses et annet sted, for eksempel på en egen side. */\n maxLines?: number;\n /** Ekstra klassenavn */\n className?: string;\n};\n\nexport type TypographyTextVariant = NonNullable<TextOwnProps['variant']>;\nexport type TypographyTextSize = NonNullable<TextOwnProps['size']>;\nexport type TypographyWeight = NonNullable<TextOwnProps['weight']>;\nexport type TypographyTone = NonNullable<TextOwnProps['tone']>;\n\nexport type TextProps<C extends React.ElementType = 'p'> =\n PolymorphicComponentProps<C, TextOwnProps>;\n\nexport type TextComponent = (<C extends React.ElementType = 'p'>(\n props: TextProps<C> & { ref?: React.Ref<Element> },\n) => React.ReactElement | null) & { displayName?: string };\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport const Text = React.forwardRef(\n <C extends React.ElementType = 'p'>(\n {\n children,\n as,\n size,\n variant,\n weight,\n tone,\n spacing,\n style,\n trim,\n maxLines,\n className,\n ...rest\n }: TextProps<C>,\n ref?: React.Ref<Element>,\n ): JSX.Element => {\n const BodyElement: React.ElementType =\n as || getSemanticTypeFromTextVariant(variant);\n const usedVariant = variant ?? getDefaultTextVariant(BodyElement);\n\n return (\n <BodyElement\n ref={ref}\n className={classNames(\n 'eds-text',\n `eds-text--${usedVariant}`,\n size && `eds-text--${size}`,\n weight && `eds-text--weight-${weight}`,\n tone && `eds-text--tone-${tone}`,\n trim && 'eds-text--trim',\n maxLines && 'eds-text--max-lines',\n className,\n )}\n style={getSpacingStyle(spacing, getMaxLinesStyle(maxLines, style))}\n {...rest}\n >\n {children}\n </BodyElement>\n );\n },\n) as TextComponent;\nText.displayName = 'Text';\n"],"names":[],"mappings":";;;;;AAmEO,MAAM,OAAO,MAAM;AAAA,EACxB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACgB;AAChB,UAAM,cACJ,MAAM,+BAA+B,OAAO;AAC9C,UAAM,cAAc,WAAW,sBAAsB,WAAW;AAEhE,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA,aAAa,WAAW;AAAA,UACxB,QAAQ,aAAa,IAAI;AAAA,UACzB,UAAU,oBAAoB,MAAM;AAAA,UACpC,QAAQ,kBAAkB,IAAI;AAAA,UAC9B,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ;AAAA,QAAA;AAAA,QAEF,OAAO,gBAAgB,SAAS,iBAAiB,UAAU,KAAK,CAAC;AAAA,QAChE,GAAG;AAAA,QAEH;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AACA,KAAK,cAAc;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
import { getSpacingStyle } from "../utils/utils.mjs";
|
|
5
|
+
/* empty css */
|
|
6
|
+
const defaultElement = "div";
|
|
7
|
+
const TextContainer = React.forwardRef(
|
|
8
|
+
({ className, spacing, style, children, as, ...rest }, ref) => {
|
|
9
|
+
const ContainerElement = as || defaultElement;
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
ContainerElement,
|
|
12
|
+
{
|
|
13
|
+
ref,
|
|
14
|
+
className: classNames("eds-text-container", className),
|
|
15
|
+
style: getSpacingStyle(spacing, style),
|
|
16
|
+
...rest,
|
|
17
|
+
children
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
TextContainer.displayName = "TextContainer";
|
|
23
|
+
export {
|
|
24
|
+
TextContainer
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=TextContainer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextContainer.mjs","sources":["../../../../src/beta/components/TextContainer.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport { TypographySpacingProps } from '../types';\nimport { getSpacingStyle } from '../utils/utils';\n\nimport './text-container.scss';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport type TextContainerOwnProps = TypographySpacingProps & {\n /** Ekstra klassenavn */\n className?: string;\n /** Overskrifter, avsnitt, lister og annen løpende tekst */\n children?: React.ReactNode;\n};\n\nexport type TextContainerProps<\n C extends React.ElementType = typeof defaultElement,\n> = PolymorphicComponentProps<C, TextContainerOwnProps>;\n\nexport type TextContainerComponent = (<\n C extends React.ElementType = typeof defaultElement,\n>(\n props: TextContainerProps<C> & { ref?: React.Ref<Element> },\n) => React.ReactElement | null) & { displayName?: string };\n\nconst defaultElement = 'div';\n\n/**\n * Gir løpende tekst riktig avstand mellom overskrifter, avsnitt og lister\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport const TextContainer = React.forwardRef(\n <C extends React.ElementType = typeof defaultElement>(\n { className, spacing, style, children, as, ...rest }: TextContainerProps<C>,\n ref?: React.Ref<Element>,\n ): JSX.Element => {\n const ContainerElement: React.ElementType = as || defaultElement;\n\n return (\n <ContainerElement\n ref={ref}\n className={classNames('eds-text-container', className)}\n style={getSpacingStyle(spacing, style)}\n {...rest}\n >\n {children}\n </ContainerElement>\n );\n },\n) as TextContainerComponent;\nTextContainer.displayName = 'TextContainer';\n"],"names":[],"mappings":";;;;;AA4BA,MAAM,iBAAiB;AAMhB,MAAM,gBAAgB,MAAM;AAAA,EACjC,CACE,EAAE,WAAW,SAAS,OAAO,UAAU,IAAI,GAAG,KAAA,GAC9C,QACgB;AAChB,UAAM,mBAAsC,MAAM;AAElD,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW,WAAW,sBAAsB,SAAS;AAAA,QACrD,OAAO,gBAAgB,SAAS,KAAK;AAAA,QACpC,GAAG;AAAA,QAEH;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AACA,cAAc,cAAc;"}
|
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import classNames from "classnames";
|
|
3
|
-
import {
|
|
4
|
+
import { getSpacingStyle } from "../utils/utils.mjs";
|
|
4
5
|
/* empty css */
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
const defaultElement = "ul";
|
|
7
|
+
const UnorderedList = React.forwardRef(
|
|
8
|
+
({
|
|
9
|
+
className,
|
|
10
|
+
tone,
|
|
11
|
+
spacing,
|
|
12
|
+
style,
|
|
13
|
+
children,
|
|
14
|
+
as,
|
|
15
|
+
...rest
|
|
16
|
+
}, ref) => {
|
|
17
|
+
const ListElement = as || defaultElement;
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
ListElement,
|
|
20
|
+
{
|
|
21
|
+
ref,
|
|
22
|
+
className: classNames(
|
|
23
|
+
"eds-text--unordered-list",
|
|
24
|
+
tone && `eds-text--tone-${tone}`,
|
|
25
|
+
className
|
|
26
|
+
),
|
|
27
|
+
style: getSpacingStyle(spacing, style),
|
|
28
|
+
role: "list",
|
|
29
|
+
...rest,
|
|
30
|
+
children
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
UnorderedList.displayName = "UnorderedList";
|
|
26
36
|
export {
|
|
27
37
|
UnorderedList
|
|
28
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnorderedList.mjs","sources":["../../../../src/beta/components/UnorderedList.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport {
|
|
1
|
+
{"version":3,"file":"UnorderedList.mjs","sources":["../../../../src/beta/components/UnorderedList.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { PolymorphicComponentProps } from '@entur/utils';\nimport { TypographySpacingProps } from '../types';\nimport { getSpacingStyle } from '../utils/utils';\n\nimport './text.scss';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport type UnorderedListOwnProps = TypographySpacingProps & {\n /** Ekstra klassenavn */\n className?: string;\n /** Dempet liste for sekundær informasjon, som hjelpetekst. Velger riktig farge i kontrast- og mørk modus. */\n tone?: 'subdued';\n /** Innholdet */\n children?: React.ReactNode;\n};\n\nexport type UnorderedListProps<\n C extends React.ElementType = typeof defaultElement,\n> = PolymorphicComponentProps<C, UnorderedListOwnProps>;\n\nexport type UnorderedListComponent = (<\n C extends React.ElementType = typeof defaultElement,\n>(\n props: UnorderedListProps<C> & { ref?: React.Ref<Element> },\n) => React.ReactElement | null) & { displayName?: string };\n\nconst defaultElement = 'ul';\n\n/**\n * @beta Experimental component - may have breaking changes in future releases\n */\nexport const UnorderedList = React.forwardRef(\n <C extends React.ElementType = typeof defaultElement>(\n {\n className,\n tone,\n spacing,\n style,\n children,\n as,\n ...rest\n }: UnorderedListProps<C>,\n ref?: React.Ref<Element>,\n ): JSX.Element => {\n const ListElement: React.ElementType = as || defaultElement;\n\n return (\n <ListElement\n ref={ref}\n className={classNames(\n 'eds-text--unordered-list',\n tone && `eds-text--tone-${tone}`,\n className,\n )}\n style={getSpacingStyle(spacing, style)}\n // Safari drops list semantics when the list has no markers\n role=\"list\"\n {...rest}\n >\n {children}\n </ListElement>\n );\n },\n) as UnorderedListComponent;\nUnorderedList.displayName = 'UnorderedList';\n"],"names":[],"mappings":";;;;;AA8BA,MAAM,iBAAiB;AAKhB,MAAM,gBAAgB,MAAM;AAAA,EACjC,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACgB;AAChB,UAAM,cAAiC,MAAM;AAE7C,WACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA,QAAQ,kBAAkB,IAAI;AAAA,UAC9B;AAAA,QAAA;AAAA,QAEF,OAAO,gBAAgB,SAAS,KAAK;AAAA,QAErC,MAAK;AAAA,QACJ,GAAG;AAAA,QAEH;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AACA,cAAc,cAAc;"}
|
package/dist/beta/esm/index.mjs
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
import { warnAboutMissingStyles } from "@entur/utils";
|
|
2
|
+
import { warnAboutGlobalStyles } from "./utils/warnAboutGlobalStyles.mjs";
|
|
1
3
|
/* empty css */
|
|
2
4
|
import { Heading } from "./components/Heading.mjs";
|
|
3
5
|
import { Text } from "./components/Text.mjs";
|
|
4
6
|
import { Link } from "./components/Link.mjs";
|
|
5
|
-
import {
|
|
7
|
+
import { Label } from "./components/Label.mjs";
|
|
6
8
|
import { UnorderedList } from "./components/UnorderedList.mjs";
|
|
7
9
|
import { NumberedList } from "./components/NumberedList.mjs";
|
|
8
10
|
import { ListItem } from "./components/ListItem.mjs";
|
|
11
|
+
import { TextContainer } from "./components/TextContainer.mjs";
|
|
12
|
+
warnAboutMissingStyles("typography");
|
|
13
|
+
warnAboutGlobalStyles();
|
|
9
14
|
export {
|
|
10
|
-
Blockquote,
|
|
11
|
-
BlockquoteFooter,
|
|
12
15
|
Heading,
|
|
16
|
+
Label,
|
|
13
17
|
Link,
|
|
14
18
|
ListItem,
|
|
15
19
|
NumberedList,
|
|
16
20
|
Text,
|
|
21
|
+
TextContainer,
|
|
17
22
|
UnorderedList
|
|
18
23
|
};
|
|
19
24
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/beta/index.tsx"],"sourcesContent":["// Beta typography components - experimental features\n// These components may have breaking changes in future releases\n\nimport { warnAboutMissingStyles } from '@entur/utils';\nimport { warnAboutGlobalStyles } from './utils/warnAboutGlobalStyles';\nimport './index.scss';\n\n// Beta still relies on the base typography styles\nwarnAboutMissingStyles('typography');\nwarnAboutGlobalStyles();\n\nexport { Heading } from './components/Heading';\nexport { Text } from './components/Text';\nexport { Link } from './components/Link';\nexport { Label } from './components/Label';\nexport { UnorderedList } from './components/UnorderedList';\nexport { NumberedList } from './components/NumberedList';\nexport { ListItem } from './components/ListItem';\nexport { TextContainer } from './components/TextContainer';\n\nexport type {\n HeadingComponent,\n HeadingOwnProps,\n HeadingProps,\n TypographyHeadingSize,\n TypographyHeadingVariant,\n} from './components/Heading';\nexport type {\n TextComponent,\n TextOwnProps,\n TextProps,\n TypographyTextSize,\n TypographyTextVariant,\n TypographyTone,\n TypographyWeight,\n} from './components/Text';\nexport type { LinkComponent, LinkOwnProps, LinkProps } from './components/Link';\nexport type { LabelOwnProps, LabelProps } from './components/Label';\nexport type {\n UnorderedListComponent,\n UnorderedListOwnProps,\n UnorderedListProps,\n} from './components/UnorderedList';\nexport type {\n NumberedListComponent,\n NumberedListOwnProps,\n NumberedListProps,\n} from './components/NumberedList';\nexport type {\n ListItemComponent,\n ListItemOwnProps,\n ListItemProps,\n} from './components/ListItem';\nexport type {\n TextContainerComponent,\n TextContainerOwnProps,\n TextContainerProps,\n} from './components/TextContainer';\n\nexport type {\n TypographySize,\n TypographySpacing,\n TypographySpacingProps,\n} from './types';\n"],"names":[],"mappings":";;;;;;;;;;;AAQA,uBAAuB,YAAY;AACnC,sBAAA;"}
|
|
@@ -1,31 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
1
|
+
const SPACING_STEPS = /* @__PURE__ */ new Set([
|
|
2
|
+
"none",
|
|
3
|
+
"2xs",
|
|
4
|
+
"xs",
|
|
5
|
+
"s",
|
|
6
|
+
"m",
|
|
7
|
+
"lg",
|
|
8
|
+
"xl",
|
|
9
|
+
"2xl",
|
|
10
|
+
"3xl",
|
|
11
|
+
"4xl",
|
|
12
|
+
"5xl",
|
|
13
|
+
"6xl",
|
|
14
|
+
"7xl",
|
|
15
|
+
"8xl",
|
|
16
|
+
"9xl",
|
|
17
|
+
"10xl",
|
|
18
|
+
"11xl",
|
|
19
|
+
"12xl",
|
|
20
|
+
"13xl"
|
|
21
|
+
]);
|
|
22
|
+
const warnedSpacing = /* @__PURE__ */ new Set();
|
|
23
|
+
function toSpacingValue(step) {
|
|
24
|
+
if (step === void 0) return void 0;
|
|
25
|
+
if (SPACING_STEPS.has(step))
|
|
26
|
+
return step === "none" ? "0px" : `var(--spacing-${step})`;
|
|
27
|
+
if (process.env.NODE_ENV !== "production" && !warnedSpacing.has(step)) {
|
|
28
|
+
warnedSpacing.add(step);
|
|
29
|
+
console.warn(
|
|
30
|
+
`[@entur/typography] spacing="${step}" er ikke en gyldig verdi og blir ignorert. Bruk none, 2xs, xs, s, m, lg, xl, 2xl … 13xl, eller { top, bottom }.`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
function getSpacingStyle(spacing, style) {
|
|
36
|
+
if (spacing === void 0) return style;
|
|
37
|
+
const { top, bottom } = typeof spacing === "object" ? spacing : { top: spacing, bottom: spacing };
|
|
38
|
+
const spacingStyle = {};
|
|
39
|
+
const topValue = toSpacingValue(top);
|
|
40
|
+
const bottomValue = toSpacingValue(bottom);
|
|
41
|
+
if (topValue) spacingStyle["--eds-text-spacing-top"] = topValue;
|
|
42
|
+
if (bottomValue) spacingStyle["--eds-text-spacing-bottom"] = bottomValue;
|
|
43
|
+
return { ...spacingStyle, ...style };
|
|
44
|
+
}
|
|
45
|
+
function getMaxLinesStyle(maxLines, style) {
|
|
46
|
+
if (!maxLines) return style;
|
|
47
|
+
return { "--eds-text-max-lines": maxLines, ...style };
|
|
25
48
|
}
|
|
26
49
|
function getHeadingVariantFromSemanticType(element) {
|
|
27
|
-
|
|
28
|
-
switch (
|
|
50
|
+
if (typeof element !== "string") return "title-2";
|
|
51
|
+
switch (element.toLowerCase()) {
|
|
29
52
|
case "h1":
|
|
30
53
|
return "title-1";
|
|
31
54
|
case "h2":
|
|
@@ -39,39 +62,48 @@ function getHeadingVariantFromSemanticType(element) {
|
|
|
39
62
|
case "h6":
|
|
40
63
|
return "section-2";
|
|
41
64
|
default:
|
|
42
|
-
return "title-
|
|
65
|
+
return "title-2";
|
|
43
66
|
}
|
|
44
67
|
}
|
|
68
|
+
const BLOCK_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
69
|
+
"p",
|
|
70
|
+
"div",
|
|
71
|
+
"li",
|
|
72
|
+
"dd",
|
|
73
|
+
"dt",
|
|
74
|
+
"figcaption"
|
|
75
|
+
]);
|
|
76
|
+
function getDefaultTextVariant(element) {
|
|
77
|
+
return typeof element === "string" && BLOCK_TEXT_ELEMENTS.has(element) ? "paragraph" : "inherit";
|
|
78
|
+
}
|
|
45
79
|
function getSemanticTypeFromTextVariant(variant) {
|
|
46
80
|
if (!variant) return "p";
|
|
47
81
|
switch (variant) {
|
|
48
|
-
case "
|
|
49
|
-
return "
|
|
50
|
-
case "
|
|
51
|
-
return "span";
|
|
52
|
-
case "caption":
|
|
53
|
-
return "span";
|
|
54
|
-
case "overline":
|
|
55
|
-
return "span";
|
|
56
|
-
case "link":
|
|
57
|
-
return "a";
|
|
58
|
-
case "code-text":
|
|
82
|
+
case "emphasized":
|
|
83
|
+
return "em";
|
|
84
|
+
case "code":
|
|
59
85
|
return "code";
|
|
60
|
-
case "preformatted
|
|
86
|
+
case "preformatted":
|
|
61
87
|
return "pre";
|
|
62
88
|
case "quote":
|
|
63
89
|
return "blockquote";
|
|
64
90
|
case "leading":
|
|
65
91
|
case "paragraph":
|
|
66
92
|
case "subparagraph":
|
|
67
|
-
case "
|
|
93
|
+
case "caption":
|
|
94
|
+
case "label":
|
|
95
|
+
case "overline":
|
|
96
|
+
case "sublabel":
|
|
68
97
|
default:
|
|
69
98
|
return "p";
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
export {
|
|
102
|
+
SPACING_STEPS,
|
|
103
|
+
getDefaultTextVariant,
|
|
73
104
|
getHeadingVariantFromSemanticType,
|
|
105
|
+
getMaxLinesStyle,
|
|
74
106
|
getSemanticTypeFromTextVariant,
|
|
75
|
-
|
|
107
|
+
getSpacingStyle
|
|
76
108
|
};
|
|
77
109
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../../src/beta/utils/utils.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../src/beta/utils/utils.ts"],"sourcesContent":["import type { TypographyHeadingVariant } from '../components/Heading';\nimport type { TypographyTextVariant } from '../components/Text';\nimport type { TypographySpacing } from '../types';\n\ntype SpacingStep = Exclude<TypographySpacing, object>;\n\n// Same scale as the layout beta, read from @entur/tokens/styles/spacing\nexport const SPACING_STEPS = new Set<string>([\n 'none',\n '2xs',\n 'xs',\n 's',\n 'm',\n 'lg',\n 'xl',\n '2xl',\n '3xl',\n '4xl',\n '5xl',\n '6xl',\n '7xl',\n '8xl',\n '9xl',\n '10xl',\n '11xl',\n '12xl',\n '13xl',\n]);\nconst warnedSpacing = new Set<string>();\n\nfunction toSpacingValue(step: SpacingStep | undefined): string | undefined {\n if (step === undefined) return undefined;\n if (SPACING_STEPS.has(step))\n // A unit keeps it valid inside calc()\n return step === 'none' ? '0px' : `var(--spacing-${step})`;\n\n if (process.env.NODE_ENV !== 'production' && !warnedSpacing.has(step)) {\n warnedSpacing.add(step);\n console.warn(\n `[@entur/typography] spacing=\"${step}\" er ikke en gyldig verdi og blir ignorert. Bruk none, 2xs, xs, s, m, lg, xl, 2xl … 13xl, eller { top, bottom }.`,\n );\n }\n return undefined;\n}\n\n/**\n * Turn the spacing prop into the custom properties that set the margins\n */\nexport function getSpacingStyle(\n spacing: TypographySpacing | undefined,\n style?: React.CSSProperties,\n): React.CSSProperties | undefined {\n if (spacing === undefined) return style;\n\n const { top, bottom } =\n typeof spacing === 'object' ? spacing : { top: spacing, bottom: spacing };\n const spacingStyle: Record<string, string> = {};\n const topValue = toSpacingValue(top);\n const bottomValue = toSpacingValue(bottom);\n if (topValue) spacingStyle['--eds-text-spacing-top'] = topValue;\n if (bottomValue) spacingStyle['--eds-text-spacing-bottom'] = bottomValue;\n\n return { ...spacingStyle, ...style };\n}\n\n/**\n * Pass maxLines on to the CSS, which cuts the text after that many lines\n */\nexport function getMaxLinesStyle(\n maxLines: number | undefined,\n style?: React.CSSProperties,\n): React.CSSProperties | undefined {\n if (!maxLines) return style;\n return { '--eds-text-max-lines': maxLines, ...style } as React.CSSProperties;\n}\n\n/**\n * Get heading variant based on semantic HTML element\n */\nexport function getHeadingVariantFromSemanticType(\n element: string | React.ElementType,\n): TypographyHeadingVariant {\n // Same as the default element, h2\n if (typeof element !== 'string') return 'title-2';\n\n switch (element.toLowerCase()) {\n case 'h1':\n return 'title-1';\n case 'h2':\n return 'title-2';\n case 'h3':\n return 'subtitle-1';\n case 'h4':\n return 'subtitle-2';\n case 'h5':\n return 'section-1';\n case 'h6':\n return 'section-2';\n default:\n return 'title-2';\n }\n}\n\n// Elements that hold a paragraph of their own; anything else sits in other text and inherits it\nconst BLOCK_TEXT_ELEMENTS = new Set([\n 'p',\n 'div',\n 'li',\n 'dd',\n 'dt',\n 'figcaption',\n]);\n\n/**\n * The variant Text uses when none is given: paragraph on its own line, inherit inside other text\n */\nexport function getDefaultTextVariant(\n element: React.ElementType,\n): 'paragraph' | 'inherit' {\n return typeof element === 'string' && BLOCK_TEXT_ELEMENTS.has(element)\n ? 'paragraph'\n : 'inherit';\n}\n\n/**\n * Get semantic HTML element from text variant\n */\nexport function getSemanticTypeFromTextVariant(\n variant: TypographyTextVariant | undefined,\n): keyof JSX.IntrinsicElements {\n if (!variant) return 'p';\n\n switch (variant) {\n case 'emphasized':\n return 'em';\n case 'code':\n return 'code';\n case 'preformatted':\n return 'pre';\n case 'quote':\n return 'blockquote';\n case 'leading':\n case 'paragraph':\n case 'subparagraph':\n case 'caption':\n case 'label':\n case 'overline':\n case 'sublabel':\n default:\n return 'p';\n }\n}\n"],"names":[],"mappings":"AAOO,MAAM,oCAAoB,IAAY;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AACD,MAAM,oCAAoB,IAAA;AAE1B,SAAS,eAAe,MAAmD;AACzE,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI,cAAc,IAAI,IAAI;AAExB,WAAO,SAAS,SAAS,QAAQ,iBAAiB,IAAI;AAExD,MAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,cAAc,IAAI,IAAI,GAAG;AACrE,kBAAc,IAAI,IAAI;AACtB,YAAQ;AAAA,MACN,gCAAgC,IAAI;AAAA,IAAA;AAAA,EAExC;AACA,SAAO;AACT;AAKO,SAAS,gBACd,SACA,OACiC;AACjC,MAAI,YAAY,OAAW,QAAO;AAElC,QAAM,EAAE,KAAK,OAAA,IACX,OAAO,YAAY,WAAW,UAAU,EAAE,KAAK,SAAS,QAAQ,QAAA;AAClE,QAAM,eAAuC,CAAA;AAC7C,QAAM,WAAW,eAAe,GAAG;AACnC,QAAM,cAAc,eAAe,MAAM;AACzC,MAAI,SAAU,cAAa,wBAAwB,IAAI;AACvD,MAAI,YAAa,cAAa,2BAA2B,IAAI;AAE7D,SAAO,EAAE,GAAG,cAAc,GAAG,MAAA;AAC/B;AAKO,SAAS,iBACd,UACA,OACiC;AACjC,MAAI,CAAC,SAAU,QAAO;AACtB,SAAO,EAAE,wBAAwB,UAAU,GAAG,MAAA;AAChD;AAKO,SAAS,kCACd,SAC0B;AAE1B,MAAI,OAAO,YAAY,SAAU,QAAO;AAExC,UAAQ,QAAQ,eAAY;AAAA,IAC1B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb;AAGA,MAAM,0CAA0B,IAAI;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKM,SAAS,sBACd,SACyB;AACzB,SAAO,OAAO,YAAY,YAAY,oBAAoB,IAAI,OAAO,IACjE,cACA;AACN;AAKO,SAAS,+BACd,SAC6B;AAC7B,MAAI,CAAC,QAAS,QAAO;AAErB,UAAQ,SAAA;AAAA,IACN,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EAAA;AAEb;"}
|