@hashicorp/mds-react 0.9.11 → 0.9.12

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,4 +1,4 @@
1
- import { ComponentPropsWithRef, ElementType } from 'react';
1
+ import { ComponentPropsWithRef, ElementType, ReactNode } from 'react';
2
2
  declare const TEXT_COLORS: readonly ["primary", "strong", "faint", "disabled", "high-contrast", "action", "action-hover", "action-active", "highlight", "highlight-on-surface", "highlight-high-contrast", "success", "success-on-surface", "success-high-contrast", "warning", "warning-on-surface", "warning-high-contrast", "critical", "critical-on-surface", "critical-high-contrast"];
3
3
  declare const TEXT_GROUPS: readonly ["hds-body", "code", "body", "display-expressive", "label"];
4
4
  declare const TEXT_SIZES: readonly ["100", "200", "300", "400", "500", "600", "700", "800"];
@@ -10,35 +10,60 @@ type TextSize = (typeof TEXT_SIZES)[number];
10
10
  type HexColor = string & {
11
11
  hexish?: unknown;
12
12
  };
13
- interface BaseTextProps<T extends ElementType> extends React.PropsWithChildren {
14
- tag?: T;
13
+ interface BaseTextProps {
15
14
  size?: TextSize;
16
15
  weight?: TextWeight;
17
16
  align?: 'left' | 'center' | 'right';
18
17
  color?: TextColor | HexColor;
19
18
  className?: string;
19
+ children?: ReactNode;
20
20
  }
21
- interface TextImplProps<T extends ElementType> extends BaseTextProps<T> {
21
+ type PolymorphicTextProps<TTag extends ElementType, OwnProps extends object> = OwnProps & {
22
+ tag?: TTag;
23
+ } & Omit<ComponentPropsWithRef<TTag>, keyof OwnProps | 'tag'>;
24
+ interface TextImplInternalProps extends BaseTextProps {
22
25
  group: TextGroup;
26
+ tag?: ElementType;
27
+ [key: string]: unknown;
23
28
  }
24
- interface BodyProps<T extends ElementType> extends BaseTextProps<T> {
29
+ /** ------------------------------------------------------------------
30
+ * Body
31
+ * ------------------------------------------------------------------ */
32
+ interface BodyOwnProps extends BaseTextProps {
25
33
  size?: '200' | '300' | '400';
26
34
  }
27
- interface DisplayExpressiveProps<T extends ElementType> extends BaseTextProps<T> {
35
+ export type BodyProps<TTag extends ElementType = 'span'> = PolymorphicTextProps<TTag, BodyOwnProps>;
36
+ /** ------------------------------------------------------------------
37
+ * DisplayExpressive
38
+ * ------------------------------------------------------------------ */
39
+ interface DisplayExpressiveOwnProps extends BaseTextProps {
28
40
  size?: '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800';
29
41
  }
30
- type LabelProps<T extends ElementType> = Omit<BaseTextProps<T>, 'size'>;
31
- interface HDSBodyProps<T extends ElementType> extends BaseTextProps<T> {
42
+ export type DisplayExpressiveProps<TTag extends ElementType = 'span'> = PolymorphicTextProps<TTag, DisplayExpressiveOwnProps>;
43
+ /** ------------------------------------------------------------------
44
+ * Label
45
+ * ------------------------------------------------------------------ */
46
+ type LabelOwnProps = Omit<BaseTextProps, 'size'>;
47
+ export type LabelProps<TTag extends ElementType = 'span'> = PolymorphicTextProps<TTag, LabelOwnProps>;
48
+ /** ------------------------------------------------------------------
49
+ * HDSBody
50
+ * ------------------------------------------------------------------ */
51
+ interface HDSBodyOwnProps extends BaseTextProps {
32
52
  size?: '100' | '200' | '300';
33
53
  }
34
- interface CodeProps<T extends ElementType> extends BaseTextProps<T> {
54
+ export type HDSBodyProps<TTag extends ElementType = 'span'> = PolymorphicTextProps<TTag, HDSBodyOwnProps>;
55
+ /** ------------------------------------------------------------------
56
+ * Code
57
+ * ------------------------------------------------------------------ */
58
+ interface CodeOwnProps extends BaseTextProps {
35
59
  size?: '100' | '200' | '300';
36
60
  }
61
+ export type CodeProps<TTag extends ElementType = 'span'> = PolymorphicTextProps<TTag, CodeOwnProps>;
37
62
  declare const Text: {
38
- Body: <T extends ElementType<any, keyof import("react").JSX.IntrinsicElements>>({ size, ...rest }: BodyProps<T> & Omit<ComponentPropsWithRef<T>, keyof BodyProps<T>>) => import('react').FunctionComponentElement<TextImplProps<ElementType<any, keyof import("react").JSX.IntrinsicElements>> & Omit<any, keyof TextImplProps<T_1>>>;
39
- DisplayExpressive: <T_2 extends ElementType<any, keyof import("react").JSX.IntrinsicElements>>({ size, ...rest }: DisplayExpressiveProps<T_2> & Omit<ComponentPropsWithRef<T_2>, keyof DisplayExpressiveProps<T_2>>) => import('react').FunctionComponentElement<TextImplProps<ElementType<any, keyof import("react").JSX.IntrinsicElements>> & Omit<any, keyof TextImplProps<T_1>>>;
40
- Label: <T_3 extends ElementType<any, keyof import("react").JSX.IntrinsicElements>>(props: LabelProps<T_3> & Omit<ComponentPropsWithRef<T_3>, "children" | "className" | "color" | "tag" | "weight" | "align">) => import('react').FunctionComponentElement<TextImplProps<ElementType<any, keyof import("react").JSX.IntrinsicElements>> & Omit<any, keyof TextImplProps<T_1>>>;
41
- HDSBody: <T_4 extends ElementType<any, keyof import("react").JSX.IntrinsicElements>>({ size, weight, ...rest }: HDSBodyProps<T_4> & Omit<ComponentPropsWithRef<T_4>, keyof HDSBodyProps<T_4>>) => import('react').FunctionComponentElement<TextImplProps<ElementType<any, keyof import("react").JSX.IntrinsicElements>> & Omit<any, keyof TextImplProps<T_1>>>;
42
- Code: <T_5 extends ElementType<any, keyof import("react").JSX.IntrinsicElements>>({ size, weight, ...rest }: CodeProps<T_5> & Omit<ComponentPropsWithRef<T_5>, keyof CodeProps<T_5>>) => import('react').FunctionComponentElement<TextImplProps<ElementType<any, keyof import("react").JSX.IntrinsicElements>> & Omit<any, keyof TextImplProps<T_1>>>;
63
+ Body: <TTag extends ElementType<any, keyof import("react").JSX.IntrinsicElements> = "span">(props: BodyProps<TTag>) => import('react').FunctionComponentElement<TextImplInternalProps>;
64
+ DisplayExpressive: <TTag_1 extends ElementType<any, keyof import("react").JSX.IntrinsicElements> = "span">(props: DisplayExpressiveProps<TTag_1>) => import('react').FunctionComponentElement<TextImplInternalProps>;
65
+ Label: <TTag_2 extends ElementType<any, keyof import("react").JSX.IntrinsicElements> = "span">(props: LabelProps<TTag_2>) => import('react').FunctionComponentElement<TextImplInternalProps>;
66
+ HDSBody: <TTag_3 extends ElementType<any, keyof import("react").JSX.IntrinsicElements> = "span">(props: HDSBodyProps<TTag_3>) => import('react').FunctionComponentElement<TextImplInternalProps>;
67
+ Code: <TTag_4 extends ElementType<any, keyof import("react").JSX.IntrinsicElements> = "span">(props: CodeProps<TTag_4>) => import('react').FunctionComponentElement<TextImplInternalProps>;
43
68
  };
44
69
  export { Text, TEXT_COLORS, TEXT_WEIGHTS };
@@ -1,8 +1,8 @@
1
1
  import { jsx as y } from "react/jsx-runtime";
2
- import l from "classnames";
3
- import { createElement as e } from "react";
4
- import m from "./style.module.scss.js";
5
- const b = [
2
+ import m from "classnames";
3
+ import { createElement as n } from "react";
4
+ import b from "./style.module.scss.js";
5
+ const f = [
6
6
  "primary",
7
7
  "strong",
8
8
  "faint",
@@ -23,90 +23,96 @@ const b = [
23
23
  "critical",
24
24
  "critical-on-surface",
25
25
  "critical-high-contrast"
26
- ], B = ["regular", "medium", "semibold", "bold"];
27
- function f(r, o) {
26
+ ], z = ["regular", "medium", "semibold", "bold"];
27
+ function T(s, t) {
28
28
  return {
29
- "hds-body": `mds-typography-legacy-body-${o}`,
30
- code: `mds-typography-code-${o}`,
31
- "display-expressive": `mds-typography-display-expressive-${o}`,
29
+ "hds-body": `mds-typography-legacy-body-${t}`,
30
+ code: `mds-typography-code-${t}`,
31
+ "display-expressive": `mds-typography-display-expressive-${t}`,
32
32
  label: "mds-typography-label",
33
- body: `mds-typography-body-${o}`
34
- }[r];
33
+ body: `mds-typography-body-${t}`
34
+ }[s];
35
35
  }
36
- const n = ({
37
- tag: r,
38
- group: o,
39
- size: s = "200",
40
- weight: a,
41
- align: c,
42
- color: t,
43
- children: p,
44
- className: g,
45
- ...d
46
- }) => {
47
- const h = r ?? "span", u = f(o, s), i = b.includes(t);
36
+ const c = (s) => {
37
+ const {
38
+ tag: t,
39
+ group: o,
40
+ size: r = "200",
41
+ weight: e,
42
+ align: i,
43
+ color: a,
44
+ children: p,
45
+ className: l,
46
+ ...d
47
+ } = s, h = t ?? "span", u = T(o, r), g = f.includes(a);
48
48
  return /* @__PURE__ */ y(
49
49
  h,
50
50
  {
51
- className: l(
51
+ className: m(
52
52
  u,
53
53
  {
54
- [m[`align-${c}`]]: c,
55
- [`mds-typography-font-weight-${a}`]: a,
56
- [`mds-foreground-${t}`]: t && i
54
+ [b[`align-${i}`]]: i,
55
+ [`mds-typography-font-weight-${e}`]: e,
56
+ [`mds-foreground-${a}`]: a && g
57
57
  },
58
- g
58
+ l
59
59
  ),
60
- style: t && !i ? { color: t } : {},
60
+ style: a && !g ? { color: a } : {},
61
61
  ...d,
62
62
  children: p
63
63
  }
64
64
  );
65
- }, T = ({
66
- size: r = "300",
67
- ...o
68
- }) => e(n, {
69
- ...o,
70
- size: r,
71
- group: "body"
72
- }), x = ({
73
- size: r = "200",
74
- ...o
75
- }) => e(n, {
76
- ...o,
77
- size: r,
78
- group: "display-expressive"
79
- }), v = (r) => e(n, {
80
- ...r,
81
- group: "label"
82
- }), $ = ({
83
- size: r = "200",
84
- weight: o = "regular",
85
- ...s
86
- }) => e(n, {
87
- ...s,
88
- size: r,
89
- weight: o,
90
- group: "hds-body"
91
- }), E = ({
92
- size: r = "200",
93
- weight: o = "regular",
94
- ...s
95
- }) => e(n, {
96
- ...s,
97
- size: r,
98
- weight: o,
99
- group: "code"
100
- }), D = {
101
- Body: T,
102
- DisplayExpressive: x,
103
- Label: v,
65
+ }, x = (s) => {
66
+ const { tag: t, size: o = "300", ...r } = s;
67
+ return n(c, {
68
+ ...r,
69
+ tag: t ?? "span",
70
+ size: o,
71
+ group: "body"
72
+ });
73
+ }, v = (s) => {
74
+ const { tag: t, size: o = "200", ...r } = s;
75
+ return n(c, {
76
+ ...r,
77
+ tag: t ?? "span",
78
+ size: o,
79
+ group: "display-expressive"
80
+ });
81
+ }, w = (s) => {
82
+ const { tag: t, ...o } = s;
83
+ return n(c, {
84
+ ...o,
85
+ tag: t ?? "span",
86
+ group: "label"
87
+ });
88
+ }, $ = (s) => {
89
+ const { tag: t, size: o = "200", weight: r = "regular", ...e } = s;
90
+ return n(c, {
91
+ ...e,
92
+ tag: t ?? "span",
93
+ size: o,
94
+ weight: r,
95
+ group: "hds-body"
96
+ });
97
+ }, E = (s) => {
98
+ const { tag: t, size: o = "200", weight: r = "regular", ...e } = s;
99
+ return n(c, {
100
+ ...e,
101
+ tag: t ?? "span",
102
+ size: o,
103
+ weight: r,
104
+ group: "code"
105
+ });
106
+ }, B = {
107
+ Body: x,
108
+ DisplayExpressive: v,
109
+ Label: w,
104
110
  HDSBody: $,
105
111
  Code: E
106
112
  };
107
113
  export {
108
- b as TEXT_COLORS,
109
- B as TEXT_WEIGHTS,
110
- D as Text
114
+ f as TEXT_COLORS,
115
+ z as TEXT_WEIGHTS,
116
+ B as Text
111
117
  };
112
118
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/text/index.tsx"],"sourcesContent":["import classNames from 'classnames'\nimport {\n\tcreateElement,\n\ttype ComponentPropsWithRef,\n\ttype ElementType,\n} from 'react'\nimport s from './style.module.scss'\n\nconst TEXT_COLORS = [\n\t'primary',\n\t'strong',\n\t'faint',\n\t'disabled',\n\t'high-contrast',\n\t'action',\n\t'action-hover',\n\t'action-active',\n\t'highlight',\n\t'highlight-on-surface',\n\t'highlight-high-contrast',\n\t'success',\n\t'success-on-surface',\n\t'success-high-contrast',\n\t'warning',\n\t'warning-on-surface',\n\t'warning-high-contrast',\n\t'critical',\n\t'critical-on-surface',\n\t'critical-high-contrast',\n] as const\n\nconst TEXT_GROUPS = [\n\t'hds-body',\n\t'code',\n\t'body',\n\t'display-expressive',\n\t'label',\n] as const\n\nconst TEXT_SIZES = [\n\t'100',\n\t'200',\n\t'300',\n\t'400',\n\t'500',\n\t'600',\n\t'700',\n\t'800',\n] as const\n\nconst TEXT_WEIGHTS = ['regular', 'medium', 'semibold', 'bold'] as const\n\ntype TextColor = (typeof TEXT_COLORS)[number]\ntype TextWeight = (typeof TEXT_WEIGHTS)[number]\ntype TextGroup = (typeof TEXT_GROUPS)[number]\ntype TextSize = (typeof TEXT_SIZES)[number]\n\n// small typescript hack to support autocomplete and arbitrary strings\ntype HexColor = string & { hexish?: unknown }\n\ninterface BaseTextProps<T extends ElementType> extends React.PropsWithChildren {\n\ttag?: T\n\tsize?: TextSize\n\tweight?: TextWeight\n\talign?: 'left' | 'center' | 'right'\n\tcolor?: TextColor | HexColor\n\tclassName?: string\n}\n\ninterface TextImplProps<T extends ElementType> extends BaseTextProps<T> {\n\tgroup: TextGroup\n}\n\nfunction getTypographyToken(group: TextGroup, size: TextSize): string {\n\tconst groupToTokenMap: Record<TextGroup, string> = {\n\t\t'hds-body': `mds-typography-legacy-body-${size}`,\n\t\tcode: `mds-typography-code-${size}`,\n\t\t'display-expressive': `mds-typography-display-expressive-${size}`,\n\t\tlabel: `mds-typography-label`,\n\t\tbody: `mds-typography-body-${size}`,\n\t}\n\n\treturn groupToTokenMap[group]\n}\n\nconst TextImpl = <T extends ElementType = 'span'>({\n\ttag,\n\tgroup,\n\tsize = '200',\n\tweight,\n\talign,\n\tcolor,\n\tchildren,\n\tclassName,\n\t...rest\n}: TextImplProps<T> &\n\tOmit<ComponentPropsWithRef<T>, keyof TextImplProps<T>>) => {\n\tconst Component = tag ?? 'span'\n\tconst variant = getTypographyToken(group, size)\n\n\tconst usesPredefinedColor = TEXT_COLORS.includes(color as TextColor)\n\n\treturn (\n\t\t<Component\n\t\t\tclassName={classNames(\n\t\t\t\tvariant,\n\t\t\t\t{\n\t\t\t\t\t[s[`align-${align}`]]: align,\n\t\t\t\t\t[`mds-typography-font-weight-${weight}`]: weight,\n\t\t\t\t\t[`mds-foreground-${color}`]: color && usesPredefinedColor,\n\t\t\t\t},\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={color && !usesPredefinedColor ? { color } : {}}\n\t\t\t{...rest}\n\t\t>\n\t\t\t{children}\n\t\t</Component>\n\t)\n}\n\ninterface BodyProps<T extends ElementType> extends BaseTextProps<T> {\n\tsize?: '200' | '300' | '400'\n}\n\nconst Body = <T extends ElementType>({\n\tsize = '300',\n\t...rest\n}: BodyProps<T> & Omit<ComponentPropsWithRef<T>, keyof BodyProps<T>>) => {\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\tsize,\n\t\tgroup: 'body',\n\t})\n}\n\ninterface DisplayExpressiveProps<T extends ElementType>\n\textends BaseTextProps<T> {\n\tsize?: '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800'\n}\n\nconst DisplayExpressive = <T extends ElementType>({\n\tsize = '200',\n\t...rest\n}: DisplayExpressiveProps<T> &\n\tOmit<ComponentPropsWithRef<T>, keyof DisplayExpressiveProps<T>>) => {\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\tsize,\n\t\tgroup: 'display-expressive',\n\t})\n}\n\ntype LabelProps<T extends ElementType> = Omit<BaseTextProps<T>, 'size'>\n\nconst Label = <T extends ElementType>(\n\tprops: LabelProps<T> & Omit<ComponentPropsWithRef<T>, keyof LabelProps<T>>\n) => {\n\treturn createElement(TextImpl, {\n\t\t...props,\n\t\tgroup: 'label',\n\t})\n}\n\ninterface HDSBodyProps<T extends ElementType> extends BaseTextProps<T> {\n\tsize?: '100' | '200' | '300'\n}\n\nconst HDSBody = <T extends ElementType>({\n\tsize = '200',\n\tweight = 'regular',\n\t...rest\n}: HDSBodyProps<T> & Omit<ComponentPropsWithRef<T>, keyof HDSBodyProps<T>>) => {\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\tsize,\n\t\tweight,\n\t\tgroup: 'hds-body',\n\t})\n}\n\ninterface CodeProps<T extends ElementType> extends BaseTextProps<T> {\n\tsize?: '100' | '200' | '300'\n}\n\nconst Code = <T extends ElementType>({\n\tsize = '200',\n\tweight = 'regular',\n\t...rest\n}: CodeProps<T> & Omit<ComponentPropsWithRef<T>, keyof CodeProps<T>>) => {\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\tsize,\n\t\tweight,\n\t\tgroup: 'code',\n\t})\n}\n\nconst Text = {\n\tBody,\n\tDisplayExpressive,\n\tLabel,\n\tHDSBody,\n\tCode,\n}\n\nexport { Text, TEXT_COLORS, TEXT_WEIGHTS }\n"],"names":["TEXT_COLORS","TEXT_WEIGHTS","getTypographyToken","group","size","TextImpl","tag","weight","align","color","children","className","rest","Component","variant","usesPredefinedColor","jsx","classNames","s","Body","createElement","DisplayExpressive","Label","props","HDSBody","Code","Text"],"mappings":";;;;AAQA,MAAMA,IAAc;AAAA,EACnB;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;AAAA,EACA;AACD,GAqBMC,IAAe,CAAC,WAAW,UAAU,YAAY,MAAM;AAuB7D,SAASC,EAAmBC,GAAkBC,GAAwB;AASrE,SARmD;AAAA,IAClD,YAAY,8BAA8BA,CAAI;AAAA,IAC9C,MAAM,uBAAuBA,CAAI;AAAA,IACjC,sBAAsB,qCAAqCA,CAAI;AAAA,IAC/D,OAAO;AAAA,IACP,MAAM,uBAAuBA,CAAI;AAAA,EAAA,EAGXD,CAAK;AAC7B;AAEA,MAAME,IAAW,CAAiC;AAAA,EACjD,KAAAC;AAAA,EACA,OAAAH;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,QAAAG;AAAA,EACA,OAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,GAAGC;AACJ,MAC4D;AAC3D,QAAMC,IAAYP,KAAO,QACnBQ,IAAUZ,EAAmBC,GAAOC,CAAI,GAExCW,IAAsBf,EAAY,SAASS,CAAkB;AAEnE,SACC,gBAAAO;AAAA,IAACH;AAAA,IAAA;AAAA,MACA,WAAWI;AAAA,QACVH;AAAA,QACA;AAAA,UACC,CAACI,EAAE,SAASV,CAAK,EAAE,CAA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js","sources":["../../../src/components/text/index.tsx"],"sourcesContent":["import classNames from 'classnames'\nimport {\n\tcreateElement,\n\ttype ComponentPropsWithRef,\n\ttype ElementType,\n\ttype ReactNode,\n} from 'react'\nimport s from './style.module.scss'\n\nconst TEXT_COLORS = [\n\t'primary',\n\t'strong',\n\t'faint',\n\t'disabled',\n\t'high-contrast',\n\t'action',\n\t'action-hover',\n\t'action-active',\n\t'highlight',\n\t'highlight-on-surface',\n\t'highlight-high-contrast',\n\t'success',\n\t'success-on-surface',\n\t'success-high-contrast',\n\t'warning',\n\t'warning-on-surface',\n\t'warning-high-contrast',\n\t'critical',\n\t'critical-on-surface',\n\t'critical-high-contrast',\n] as const\n\nconst TEXT_GROUPS = [\n\t'hds-body',\n\t'code',\n\t'body',\n\t'display-expressive',\n\t'label',\n] as const\n\nconst TEXT_SIZES = [\n\t'100',\n\t'200',\n\t'300',\n\t'400',\n\t'500',\n\t'600',\n\t'700',\n\t'800',\n] as const\n\nconst TEXT_WEIGHTS = ['regular', 'medium', 'semibold', 'bold'] as const\n\ntype TextColor = (typeof TEXT_COLORS)[number]\ntype TextWeight = (typeof TEXT_WEIGHTS)[number]\ntype TextGroup = (typeof TEXT_GROUPS)[number]\ntype TextSize = (typeof TEXT_SIZES)[number]\n\n// small typescript hack to support autocomplete and arbitrary strings\ntype HexColor = string & { hexish?: unknown }\n\ninterface BaseTextProps {\n\tsize?: TextSize\n\tweight?: TextWeight\n\talign?: 'left' | 'center' | 'right'\n\tcolor?: TextColor | HexColor\n\tclassName?: string\n\tchildren?: ReactNode\n}\n\ntype PolymorphicTextProps<\n\tTTag extends ElementType,\n\tOwnProps extends object\n> = OwnProps & {\n\ttag?: TTag\n} & Omit<ComponentPropsWithRef<TTag>, keyof OwnProps | 'tag'>\n\ninterface TextImplInternalProps extends BaseTextProps {\n\tgroup: TextGroup\n\ttag?: ElementType\n\t// allow any other intrinsic props to pass through\n\t[key: string]: unknown\n}\n\nfunction getTypographyToken(group: TextGroup, size: TextSize): string {\n\tconst groupToTokenMap: Record<TextGroup, string> = {\n\t\t'hds-body': `mds-typography-legacy-body-${size}`,\n\t\tcode: `mds-typography-code-${size}`,\n\t\t'display-expressive': `mds-typography-display-expressive-${size}`,\n\t\tlabel: `mds-typography-label`,\n\t\tbody: `mds-typography-body-${size}`,\n\t}\n\n\treturn groupToTokenMap[group]\n}\n\nconst TextImpl = (props: TextImplInternalProps) => {\n\tconst {\n\t\ttag,\n\t\tgroup,\n\t\tsize = '200',\n\t\tweight,\n\t\talign,\n\t\tcolor,\n\t\tchildren,\n\t\tclassName,\n\t\t...rest\n\t} = props\n\n\tconst Component = (tag ?? 'span') as ElementType\n\tconst variant = getTypographyToken(group, size)\n\n\tconst usesPredefinedColor = TEXT_COLORS.includes(color as TextColor)\n\n\treturn (\n\t\t<Component\n\t\t\tclassName={classNames(\n\t\t\t\tvariant,\n\t\t\t\t{\n\t\t\t\t\t[s[`align-${align}`]]: align,\n\t\t\t\t\t[`mds-typography-font-weight-${weight}`]: weight,\n\t\t\t\t\t[`mds-foreground-${color}`]: color && usesPredefinedColor,\n\t\t\t\t},\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={color && !usesPredefinedColor ? { color } : {}}\n\t\t\t{...rest}\n\t\t>\n\t\t\t{children}\n\t\t</Component>\n\t)\n}\n\n/** ------------------------------------------------------------------\n * Body\n * ------------------------------------------------------------------ */\n\ninterface BodyOwnProps extends BaseTextProps {\n\tsize?: '200' | '300' | '400'\n}\n\nexport type BodyProps<TTag extends ElementType = 'span'> = PolymorphicTextProps<\n\tTTag,\n\tBodyOwnProps\n>\n\nconst Body = <TTag extends ElementType = 'span'>(props: BodyProps<TTag>) => {\n\tconst { tag, size = '300', ...rest } = props\n\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\ttag: (tag ?? 'span') as ElementType,\n\t\tsize,\n\t\tgroup: 'body' as const,\n\t})\n}\n\n/** ------------------------------------------------------------------\n * DisplayExpressive\n * ------------------------------------------------------------------ */\n\ninterface DisplayExpressiveOwnProps extends BaseTextProps {\n\tsize?: '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800'\n}\n\nexport type DisplayExpressiveProps<TTag extends ElementType = 'span'> =\n\tPolymorphicTextProps<TTag, DisplayExpressiveOwnProps>\n\nconst DisplayExpressive = <TTag extends ElementType = 'span'>(\n\tprops: DisplayExpressiveProps<TTag>\n) => {\n\tconst { tag, size = '200', ...rest } = props\n\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\ttag: (tag ?? 'span') as ElementType,\n\t\tsize,\n\t\tgroup: 'display-expressive' as const,\n\t})\n}\n\n/** ------------------------------------------------------------------\n * Label\n * ------------------------------------------------------------------ */\n\ntype LabelOwnProps = Omit<BaseTextProps, 'size'>\n\nexport type LabelProps<TTag extends ElementType = 'span'> =\n\tPolymorphicTextProps<TTag, LabelOwnProps>\n\nconst Label = <TTag extends ElementType = 'span'>(props: LabelProps<TTag>) => {\n\tconst { tag, ...rest } = props\n\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\ttag: (tag ?? 'span') as ElementType,\n\t\tgroup: 'label' as const,\n\t})\n}\n\n/** ------------------------------------------------------------------\n * HDSBody\n * ------------------------------------------------------------------ */\n\ninterface HDSBodyOwnProps extends BaseTextProps {\n\tsize?: '100' | '200' | '300'\n}\n\nexport type HDSBodyProps<TTag extends ElementType = 'span'> =\n\tPolymorphicTextProps<TTag, HDSBodyOwnProps>\n\nconst HDSBody = <TTag extends ElementType = 'span'>(\n\tprops: HDSBodyProps<TTag>\n) => {\n\tconst { tag, size = '200', weight = 'regular', ...rest } = props\n\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\ttag: (tag ?? 'span') as ElementType,\n\t\tsize,\n\t\tweight,\n\t\tgroup: 'hds-body' as const,\n\t})\n}\n\n/** ------------------------------------------------------------------\n * Code\n * ------------------------------------------------------------------ */\n\ninterface CodeOwnProps extends BaseTextProps {\n\tsize?: '100' | '200' | '300'\n}\n\nexport type CodeProps<TTag extends ElementType = 'span'> = PolymorphicTextProps<\n\tTTag,\n\tCodeOwnProps\n>\n\nconst Code = <TTag extends ElementType = 'span'>(props: CodeProps<TTag>) => {\n\tconst { tag, size = '200', weight = 'regular', ...rest } = props\n\n\treturn createElement(TextImpl, {\n\t\t...rest,\n\t\ttag: (tag ?? 'span') as ElementType,\n\t\tsize,\n\t\tweight,\n\t\tgroup: 'code' as const,\n\t})\n}\n\nconst Text = {\n\tBody,\n\tDisplayExpressive,\n\tLabel,\n\tHDSBody,\n\tCode,\n}\n\nexport { Text, TEXT_COLORS, TEXT_WEIGHTS }\n"],"names":["TEXT_COLORS","TEXT_WEIGHTS","getTypographyToken","group","size","TextImpl","props","tag","weight","align","color","children","className","rest","Component","variant","usesPredefinedColor","jsx","classNames","s","Body","createElement","DisplayExpressive","Label","HDSBody","Code","Text"],"mappings":";;;;AASA,MAAMA,IAAc;AAAA,EACnB;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;AAAA,EACA;AACD,GAqBMC,IAAe,CAAC,WAAW,UAAU,YAAY,MAAM;AAiC7D,SAASC,EAAmBC,GAAkBC,GAAwB;AASrE,SARmD;AAAA,IAClD,YAAY,8BAA8BA,CAAI;AAAA,IAC9C,MAAM,uBAAuBA,CAAI;AAAA,IACjC,sBAAsB,qCAAqCA,CAAI;AAAA,IAC/D,OAAO;AAAA,IACP,MAAM,uBAAuBA,CAAI;AAAA,EAAA,EAGXD,CAAK;AAC7B;AAEA,MAAME,IAAW,CAACC,MAAiC;AAClD,QAAM;AAAA,IACL,KAAAC;AAAA,IACA,OAAAJ;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,QAAAI;AAAA,IACA,OAAAC;AAAA,IACA,OAAAC;AAAA,IACA,UAAAC;AAA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AACJ,QAAM,EAAE,KAAAC,GAAK,MAAAH,IAAO,OAAO,QAAAI,IAAS,WAAW,GAAGK,MAASP;AAE3D,SAAOe,EAAchB,GAAU;AAAA,IAC9B,GAAGQ;AAAA,IACH,KAAMN,KAAO;AAAA,IACb,MAAAH;AAAA,IACA,QAAAI;AAAA,IACA,OAAO;AAAA,EAAA,CACP;AACF,GAeMiB,IAAO,CAAoCnB,MAA2B;AAC3E,QAAM,EAAE,KAAAC,GAAK,MAAAH,IAAO,OAAO,QAAAI,IAAS,WAAW,GAAGK,MAASP;AAE3D,SAAOe,EAAchB,GAAU;AAAA,IAC9B,GAAGQ;AAAA,IACH,KAAMN,KAAO;AAAA,IACb,MAAAH;AAAA,IACA,QAAAI;AAAA,IACA,OAAO;AAAA,EAAA,CACP;AACF,GAEMkB,IAAO;AAAA,EACZ,MAAAN;AAAA,EACA,mBAAAE;AAAA,EACA,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,MAAAC;AACD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashicorp/mds-react",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
4
4
  "description": "Materia Design System React components",
5
5
  "author": "HashiCorp",
6
6
  "license": "MPL-2.0",