@wonderflow/react-components 12.1.4 → 12.3.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.
Files changed (90) hide show
  1. package/dist/components/icon-button/icon-button.module.css +1 -1
  2. package/dist/components/index.d.ts +1 -0
  3. package/dist/components/index.d.ts.map +1 -1
  4. package/dist/components/index.js +1 -0
  5. package/dist/components/menu/menu-item/menu-item.d.ts +2 -2
  6. package/dist/components/menu/menu-item/menu-item.d.ts.map +1 -1
  7. package/dist/components/menu/menu-item/menu-item.js +1 -1
  8. package/dist/components/menu/menu-item/menu-item.stories.d.ts +43 -3
  9. package/dist/components/menu/menu-item/menu-item.stories.d.ts.map +1 -1
  10. package/dist/components/menu/menu.stories.d.ts +140 -10
  11. package/dist/components/menu/menu.stories.d.ts.map +1 -1
  12. package/dist/components/product-card/index.d.ts +3 -0
  13. package/dist/components/product-card/index.d.ts.map +1 -0
  14. package/dist/components/product-card/index.js +16 -0
  15. package/dist/components/product-card/product-card-footer/product-card-footer.d.ts +10 -0
  16. package/dist/components/product-card/product-card-footer/product-card-footer.d.ts.map +1 -0
  17. package/dist/components/product-card/product-card-footer/product-card-footer.js +20 -0
  18. package/dist/components/product-card/product-card-footer/product-card-footer.test.d.ts +2 -0
  19. package/dist/components/product-card/product-card-footer/product-card-footer.test.d.ts.map +1 -0
  20. package/dist/components/product-card/product-card-footer/product-card-footer.test.js +13 -0
  21. package/dist/components/product-card/product-card-header/product-card-header.d.ts +34 -0
  22. package/dist/components/product-card/product-card-header/product-card-header.d.ts.map +1 -0
  23. package/dist/components/product-card/product-card-header/product-card-header.js +32 -0
  24. package/dist/components/product-card/product-card-header/product-card-header.module.css +1 -0
  25. package/dist/components/product-card/product-card-header/product-card-header.test.d.ts +2 -0
  26. package/dist/components/product-card/product-card-header/product-card-header.test.d.ts.map +1 -0
  27. package/dist/components/product-card/product-card-header/product-card-header.test.js +17 -0
  28. package/dist/components/product-card/product-card-kpis/product-card-kpis.d.ts +84 -0
  29. package/dist/components/product-card/product-card-kpis/product-card-kpis.d.ts.map +1 -0
  30. package/dist/components/product-card/product-card-kpis/product-card-kpis.js +98 -0
  31. package/dist/components/product-card/product-card-kpis/product-card-kpis.module.css +1 -0
  32. package/dist/components/product-card/product-card-kpis/product-card.kpis.test.d.ts +2 -0
  33. package/dist/components/product-card/product-card-kpis/product-card.kpis.test.d.ts.map +1 -0
  34. package/dist/components/product-card/product-card-kpis/product-card.kpis.test.js +17 -0
  35. package/dist/components/product-card/product-card-media/product-card-media.d.ts +18 -0
  36. package/dist/components/product-card/product-card-media/product-card-media.d.ts.map +1 -0
  37. package/dist/components/product-card/product-card-media/product-card-media.js +53 -0
  38. package/dist/components/product-card/product-card-media/product-card-media.module.css +1 -0
  39. package/dist/components/product-card/product-card-media/product-card-media.test.d.ts +2 -0
  40. package/dist/components/product-card/product-card-media/product-card-media.test.d.ts.map +1 -0
  41. package/dist/components/product-card/product-card-media/product-card-media.test.js +29 -0
  42. package/dist/components/product-card/product-card.d.ts +43 -0
  43. package/dist/components/product-card/product-card.d.ts.map +1 -0
  44. package/dist/components/product-card/product-card.js +43 -0
  45. package/dist/components/product-card/product-card.module.css +1 -0
  46. package/dist/components/product-card/product-card.stories.d.ts +12 -0
  47. package/dist/components/product-card/product-card.stories.d.ts.map +1 -0
  48. package/dist/components/product-card/product-card.stories.js +118 -0
  49. package/dist/components/product-card/product-card.test.d.ts +2 -0
  50. package/dist/components/product-card/product-card.test.d.ts.map +1 -0
  51. package/dist/components/product-card/product-card.test.js +36 -0
  52. package/dist/components/select/select.d.ts +8 -0
  53. package/dist/components/select/select.d.ts.map +1 -1
  54. package/dist/components/select/select.js +2 -2
  55. package/dist/components/select/select.module.css +1 -1
  56. package/dist/components/select/select.stories.d.ts +3 -0
  57. package/dist/components/select/select.stories.d.ts.map +1 -1
  58. package/dist/components/select/select.stories.js +4 -0
  59. package/dist/components/snackbar/snackbar.module.css +1 -1
  60. package/dist/components/symbol/symbol.d.ts.map +1 -1
  61. package/dist/components/symbol/symbol.js +3 -1
  62. package/dist/components/symbol/symbol.module.css +1 -1
  63. package/dist/components/text/text.stories.js +1 -1
  64. package/dist/components/textfield/base-field/base-field.module.css +1 -1
  65. package/dist/components/textfield/textfield.d.ts +8 -0
  66. package/dist/components/textfield/textfield.d.ts.map +1 -1
  67. package/dist/components/textfield/textfield.js +15 -4
  68. package/dist/components/textfield/textfield.module.css +1 -1
  69. package/dist/components/textfield/textfield.stories.d.ts.map +1 -1
  70. package/dist/components/textfield/textfield.stories.js +6 -2
  71. package/dist/components/tooltip/tooltip.module.css +1 -1
  72. package/dist/examples/shell.stories.d.ts.map +1 -1
  73. package/dist/examples/shell.stories.js +2 -2
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +1 -0
  77. package/dist/utils/browser.d.ts +1 -1
  78. package/dist/utils/browser.d.ts.map +1 -1
  79. package/dist/utils/browser.js +1 -1
  80. package/dist/utils/browser.test.js +2 -2
  81. package/dist/utils/formatting.d.ts +16 -0
  82. package/dist/utils/formatting.d.ts.map +1 -0
  83. package/dist/utils/formatting.js +76 -0
  84. package/dist/utils/formatting.test.d.ts +2 -0
  85. package/dist/utils/formatting.test.d.ts.map +1 -0
  86. package/dist/utils/formatting.test.js +151 -0
  87. package/dist/utils/index.d.ts +5 -0
  88. package/dist/utils/index.d.ts.map +1 -0
  89. package/dist/utils/index.js +19 -0
  90. package/package.json +3 -3
@@ -22,6 +22,10 @@ const story = {
22
22
  options: [true, false],
23
23
  control: { type: 'inline-radio' },
24
24
  },
25
+ invalid: {
26
+ options: [true, false],
27
+ control: { type: 'inline-radio' },
28
+ },
25
29
  },
26
30
  args: {
27
31
  dimension: 'regular',
@@ -1 +1 @@
1
- @layer components{.Snackbar{background:var(--global-background);border:1px solid var(--global-vibrancy-background);border-radius:.5rem;display:block;overflow:hidden;padding:1rem}.Snackbar p{font-size:.875rem}.Snackbar[data-snackbar-kind=neutral]{--heading-foreground:var(--highlight-gray-foreground);--snackbar-bg:var(--highlight-gray-background);--snackbar-fg:var(--highlight-gray-foreground)}.Snackbar[data-snackbar-kind=positive]{--heading-foreground:var(--highlight-green-foreground);--snackbar-bg:var(--highlight-green-background);--snackbar-fg:var(--highlight-green-foreground)}.Snackbar[data-snackbar-kind=warning]{--heading-foreground:var(--highlight-yellow-foreground);--snackbar-bg:var(--highlight-yellow-background);--snackbar-fg:var(--highlight-yellow-foreground)}.Snackbar[data-snackbar-kind=info]{--heading-foreground:var(--highlight-blue-foreground);--snackbar-bg:var(--highlight-blue-background);--snackbar-fg:var(--highlight-blue-foreground)}.Snackbar[data-snackbar-kind=danger]{--heading-foreground:var(--highlight-red-foreground);--snackbar-bg:var(--highlight-red-background);--snackbar-fg:var(--highlight-red-foreground)}.Icon{color:var(--snackbar-fg);flex-grow:0;flex-shrink:0;height:1.5rem;margin-top:.2rem;max-width:1.5rem;width:1.5rem}.Icon[data-snackbar-has-title=true]{margin-top:0}}@layer overrides{.Action{background-color:var(--snackbar-fg);color:var(--snackbar-bg)}.Action:is(:active,:hover){background-color:var(--snackbar-fg);color:var(--snackbar-bg);opacity:.8}}
1
+ @layer components{.Snackbar{background:var(--global-background);border:1px solid var(--global-vibrancy-background);border-radius:.5rem;display:block;overflow:hidden;padding:1rem}.Snackbar p{font-size:.875rem}.Snackbar[data-snackbar-kind=neutral]{--heading-foreground:var(--highlight-gray-foreground);--snackbar-bg:var(--highlight-gray-background);--snackbar-fg:var(--highlight-gray-foreground)}.Snackbar[data-snackbar-kind=positive]{--heading-foreground:var(--highlight-green-foreground);--snackbar-bg:var(--highlight-green-background);--snackbar-fg:var(--highlight-green-foreground)}.Snackbar[data-snackbar-kind=warning]{--heading-foreground:var(--highlight-yellow-foreground);--snackbar-bg:var(--highlight-yellow-background);--snackbar-fg:var(--highlight-yellow-foreground)}.Snackbar[data-snackbar-kind=info]{--heading-foreground:var(--highlight-blue-foreground);--snackbar-bg:var(--highlight-blue-background);--snackbar-fg:var(--highlight-blue-foreground)}.Snackbar[data-snackbar-kind=danger]{--heading-foreground:var(--highlight-red-foreground);--snackbar-bg:var(--highlight-red-background);--snackbar-fg:var(--highlight-red-foreground)}.Icon{color:var(--snackbar-fg);flex-grow:0;flex-shrink:0;height:1.5rem;margin-top:-.15rem;max-width:1.5rem;width:1.5rem}.Icon[data-snackbar-has-title=true]{margin-top:0}}@layer overrides{.Action{background-color:var(--snackbar-fg);color:var(--snackbar-bg)}.Action:is(:active,:hover){background-color:var(--snackbar-fg);color:var(--snackbar-bg);opacity:.8}}
@@ -1 +1 @@
1
- {"version":3,"file":"symbol.d.ts","sourceRoot":"","sources":["../../../src/components/symbol/symbol.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,EAIL,YAAY,EACZ,aAAa,EAEd,MAAM,OAAO,CAAC;AAIf,oBAAY,WAAW,GAAG,aAAa,CAAC,UAAU,GAAG,aAAa,CAAC,GAAG;IACpE;;;;;OAKG;IACH,MAAM,EAAE,WAAW,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACrD;;;OAGG;IACH,SAAS,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC;;;;;MAKE;IACF,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;CAC1C,CAAA;AAED,eAAO,MAAM,MAAM;IArBjB;;;;;OAKG;YACK,WAAW,GAAG,aAAa,gBAAgB,CAAC;IACpD;;;OAGG;;IAEH;;;;;MAKE;;iDAyCF,CAAC"}
1
+ {"version":3,"file":"symbol.d.ts","sourceRoot":"","sources":["../../../src/components/symbol/symbol.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,EAIL,YAAY,EACZ,aAAa,EAEd,MAAM,OAAO,CAAC;AAIf,oBAAY,WAAW,GAAG,aAAa,CAAC,UAAU,GAAG,aAAa,CAAC,GAAG;IACpE;;;;;OAKG;IACH,MAAM,EAAE,WAAW,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACrD;;;OAGG;IACH,SAAS,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC;;;;;MAKE;IACF,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;CAC1C,CAAA;AAED,eAAO,MAAM,MAAM;IArBjB;;;;;OAKG;YACK,WAAW,GAAG,aAAa,gBAAgB,CAAC;IACpD;;;OAGG;;IAEH;;;;;MAKE;;iDA4CF,CAAC"}
@@ -6,13 +6,15 @@ import { Children, cloneElement, forwardRef, useMemo, } from 'react';
6
6
  import * as styles from './symbol.module.css';
7
7
  export const Symbol = forwardRef(({ className, source, dimension = 16, weight = 'outline', fill, ...otherProps }, forwardedRef) => {
8
8
  const computedStyle = useMemo(() => (+dimension < 18 ? 'solid' : weight), [weight, dimension]);
9
+ const colorFill = { '--fill': fill ?? otherProps.color ?? 'currentcolor' };
9
10
  return (typeof source === 'string')
10
- ? (_jsx("svg", { "aria-hidden": "true", width: dimension, height: dimension, fill: fill, className: clsx(styles.Icon, className), ref: forwardedRef, ...otherProps, children: _jsx("use", { href: `${sprite}#${computedStyle}/${source}` }) }))
11
+ ? (_jsx("svg", { "aria-hidden": "true", width: dimension, height: dimension, fill: fill, className: clsx(styles.Icon, className), style: colorFill, ref: forwardedRef, ...otherProps, children: _jsx("use", { href: `${sprite}#${computedStyle}/${source}` }) }))
11
12
  : (_jsx(_Fragment, { children: Children.map(source, (child) => cloneElement(child, {
12
13
  className,
13
14
  'aria-hidden': 'true',
14
15
  width: dimension,
15
16
  height: dimension,
17
+ color: fill ?? 'currentcolor',
16
18
  })) }));
17
19
  });
18
20
  Symbol.displayName = 'Symbol';
@@ -1 +1 @@
1
- @layer components{.Icon [fill]{fill:currentcolor}.Icon [fill=none][stroke]{fill:none;stroke:currentcolor}}
1
+ @layer components{.Icon{color:var(--fill)}.Icon [fill]{fill:currentcolor}.Icon [fill=none][stroke]{fill:none;stroke:currentcolor}}
@@ -77,7 +77,7 @@ withConstraint.args = {
77
77
  const TemplateDecorators = () => {
78
78
  const variants = ['body-1', 'body-2', 'body-3'];
79
79
  const sizes = ['small', 'medium', 'big'];
80
- return (_jsx(Container, { dimension: "fixed", children: _jsx(Stack, { rowGap: 40, children: variants.map(v => (_jsxs(Stack, { rowGap: 8, children: [_jsx(Text, { variant: v, color: "informative", decoratorSize: sizes[0], decoratorStart: _jsx(Symbol, { source: "circle-check", weight: "solid" }), decoratorEnd: _jsx(Chip, { color: "cyan", children: sizes[0] }), children: v }), _jsx(Text, { variant: v, decoratorSize: sizes[1], decoratorStart: _jsx(Symbol, { source: "circle-check", weight: "solid" }), decoratorEnd: _jsx(Chip, { color: "green", children: sizes[1] }), children: v }), _jsx(Text, { variant: v, decoratorSize: sizes[2], decoratorStart: _jsx(Symbol, { source: "circle-check", weight: "outline", color: "red" }), decoratorEnd: _jsx(Chip, { color: "red", children: sizes[2] }), children: v })] }, v))) }) }));
80
+ return (_jsx(Container, { dimension: "fixed", children: _jsx(Stack, { rowGap: 40, children: variants.map(v => (_jsxs(Stack, { rowGap: 8, children: [_jsx(Text, { variant: v, color: "informative", decoratorSize: sizes[0], decoratorStart: _jsx(Symbol, { source: "circle-check", weight: "solid" }), decoratorEnd: _jsx(Chip, { color: "cyan", children: sizes[0] }), children: v }), _jsx(Text, { variant: v, decoratorSize: sizes[1], decoratorStart: _jsx(Symbol, { source: "circle-check", weight: "solid" }), decoratorEnd: _jsx(Chip, { color: "green", children: sizes[1] }), children: v }), _jsx(Text, { variant: v, decoratorSize: sizes[2], decoratorStart: _jsx(Symbol, { source: "circle-check", weight: "outline", color: "var(--highlight-red-foreground)" }), decoratorEnd: _jsx(Chip, { color: "red", children: sizes[2] }), children: v })] }, v))) }) }));
81
81
  };
82
82
  export const withDecorators = TemplateDecorators.bind({});
83
83
  const TemplatePairing = () => (_jsxs(Stack, { rowGap: 32, children: [_jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "display-1", preventResponsive: true, children: "96px display-1" }), _jsx(Text, { variant: "tagline-1", preventResponsive: true, children: "28px tagline-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "display-2", preventResponsive: true, children: "80px display-2" }), _jsx(Text, { variant: "tagline-1", preventResponsive: true, children: "28px tagline-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "display-3", preventResponsive: true, children: "68px display-3" }), _jsx(Text, { variant: "tagline-2", preventResponsive: true, children: "24px tagline-2 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "display-4", preventResponsive: true, children: "56px display-4" }), _jsx(Text, { variant: "tagline-2", preventResponsive: true, children: "24px tagline-2 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "tagline-3", preventResponsive: true, children: "20px tagline-3" }), _jsx(Text, { variant: "heading-1", preventResponsive: true, children: "48px heading-1" }), _jsx(Text, { variant: "tagline-3", children: "20px tagline-3" })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "subtitle-1", children: "16px subtitle-1" }), _jsx(Text, { variant: "heading-1", preventResponsive: true, children: "48px heading-1" }), _jsx(Text, { variant: "body-1", children: "16px body-1" })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "heading-1", preventResponsive: true, children: "48px heading-1" }), _jsx(Text, { variant: "body-1", children: "16px as body-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "heading-2", preventResponsive: true, children: "40px heading-2" }), _jsx(Text, { variant: "body-1", children: "16px as body-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { children: [_jsx(Text, { variant: "subtitle-1", color: "danger", children: "Heading Title with Body text" }), _jsx(Separator, {})] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "heading-3", preventResponsive: true, children: "32px heading-3" }), _jsx(Text, { variant: "body-1", children: "16px as body-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "heading-4", preventResponsive: true, children: "28px heading-4" }), _jsx(Text, { variant: "body-1", children: "16px as body-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "heading-5", preventResponsive: true, children: "24px heading-5" }), _jsx(Text, { variant: "body-1", children: "16px as body-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "heading-6", preventResponsive: true, children: "20px heading-6" }), _jsx(Text, { variant: "body-1", children: "16px as body-1 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "heading-6", preventResponsive: true, children: "20px heading-6" }), _jsx(Text, { variant: "body-2", children: "14px as body-2 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "subtitle-1", children: "16px subtitle-1" }), _jsx(Text, { variant: "body-2", children: "14px as body-2 Lorem ipsum sit amet, consectur adipiscing elit. Fusce aliquet cursus." })] }), _jsxs("div", { children: [_jsx(Text, { variant: "subtitle-1", color: "danger", children: "Title with eyebrow text" }), _jsx(Separator, {})] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "subtitle-1", children: "16px subtitle-1" }), _jsx(Text, { variant: "heading-4", preventResponsive: true, children: "28px heading-4" })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "subtitle-2", children: "14px subtitle-2" }), _jsx(Text, { variant: "heading-5", preventResponsive: true, children: "24px heading-5" })] }), _jsxs("div", { children: [_jsx(Text, { variant: "subtitle-1", color: "danger", children: "Paragraph with text" }), _jsx(Separator, {})] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { children: "16px as body-1" }), _jsx(Text, { variant: "body-3", children: "12px as body-3" })] }), _jsxs("div", { style: { maxWidth: '800px' }, children: [_jsx(Text, { variant: "body-2", children: "14px as body-2" }), _jsx(Text, { variant: "body-3", children: "12px as body-3" })] })] }));
@@ -1 +1 @@
1
- @layer components{.BaseField{appearance:none;background-color:var(--global-background);block-size:var(--field-height);border:1px solid var(--dimmed-2);border-radius:.25rem;box-sizing:border-box;caret-color:var(--cta-default);color:inherit;display:flex;font-family:inherit;font-size:var(--font-size);inline-size:100%;line-height:1rem;margin:0;overflow:hidden;padding:0 var(--field-padding);text-overflow:ellipsis}[data-textfield-has-icon=true] .BaseField::-webkit-calendar-picker-indicator{opacity:0;position:absolute;right:calc(var(--field-padding)/2)}.BaseField:-moz-ui-invalid{box-shadow:none}.BaseField::placeholder{color:var(--dimmed-5)}.BaseField:focus-visible{border-color:var(--dimmed-5)}.BaseField:disabled{background:linear-gradient(to bottom,var(--global-disabled-background),var(--global-disabled-background));border-color:transparent;color:var(--global-disabled-foreground);cursor:not-allowed}.BaseField:disabled::placeholder{color:var(--global-disabled-foreground)}.BaseField[readonly]{border-style:dashed;box-shadow:none;cursor:default}.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:active,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:hover{-webkit-text-fill-color:var(--global-vibrancy-foreground);border:1px solid var(--dimmed-2);box-shadow:0 0 0 100px var(--global-background) inset}:is(.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:hover,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:active)::selection{-webkit-text-fill-color:var(--dimmed-0)}.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range),.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range):focus-visible{border-color:var(--highlight-red-foreground)}.BaseField[type=number]{appearance:textfield}.BaseField[type=number]::-webkit-inner-spin-button,.BaseField[type=number]::-webkit-outer-spin-button{display:none}.BaseField[type=search]{appearance:none}.BaseField[type=search]::-webkit-search-cancel-button,.BaseField[type=search]::-webkit-search-decoration{appearance:none}textarea.BaseField{block-size:auto;line-height:1.5rem;min-block-size:2rem;padding:calc(var(--field-padding)/2) calc(var(--field-padding) + 1rem) calc(var(--field-padding)/2) var(--field-padding);resize:vertical}textarea.BaseField::-webkit-datetime-edit-text{opacity:.3}textarea.BaseField::-webkit-calendar-picker-indicator{color:var(--global-foreground)}textarea.BaseField:-moz-ui-invalid{box-shadow:none}textarea.BaseField::-webkit-calendar-picker-indicator:hover{background-color:transparent}}
1
+ @layer components{.BaseField{appearance:none;background-color:var(--global-background);block-size:var(--field-height);border:1px solid var(--dimmed-2);border-radius:.25rem;box-sizing:border-box;caret-color:var(--cta-default);color:inherit;display:flex;font-family:inherit;font-size:var(--font-size);inline-size:100%;line-height:1rem;margin:0;overflow:hidden;padding:0 var(--field-padding);text-overflow:ellipsis}.BaseField::-webkit-calendar-picker-indicator{filter:invert(13%) sepia(1%) saturate(2042%) hue-rotate(315deg) brightness(76%) contrast(75%)}[data-textfield-has-icon=true] .BaseField::-webkit-calendar-picker-indicator{opacity:0;position:absolute;right:calc(var(--field-padding)/2)}.BaseField:-moz-ui-invalid{box-shadow:none}.BaseField::placeholder{color:var(--dimmed-5)}.BaseField:focus-visible{border-color:var(--dimmed-5)}.BaseField:disabled{background:linear-gradient(to bottom,var(--global-disabled-background),var(--global-disabled-background));border-color:transparent;color:var(--global-disabled-foreground);cursor:not-allowed}.BaseField:disabled::placeholder{color:var(--global-disabled-foreground)}.BaseField[readonly]{border-style:dashed;box-shadow:none;cursor:default}.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:active,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:hover{-webkit-text-fill-color:var(--global-vibrancy-foreground);border:1px solid var(--dimmed-2);box-shadow:0 0 0 100px var(--global-background) inset}:is(.BaseField:-webkit-autofill,.BaseField:-webkit-autofill:hover,.BaseField:-webkit-autofill:focus,.BaseField:-webkit-autofill:active)::selection{-webkit-text-fill-color:var(--dimmed-0)}.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range),.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range):focus-visible{border-color:var(--highlight-red-foreground)}:is(.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range),.BaseField:is(:invalid,[data-basefield-invalid=true],:out-of-range):focus-visible)::-webkit-calendar-picker-indicator{filter:invert(13%) sepia(87%) saturate(5603%) hue-rotate(346deg) brightness(55%) contrast(100%)}.BaseField[type=number]{appearance:textfield}.BaseField[type=number]::-webkit-inner-spin-button,.BaseField[type=number]::-webkit-outer-spin-button{display:none}.BaseField[type=search]{appearance:none}.BaseField[type=search]::-webkit-search-cancel-button,.BaseField[type=search]::-webkit-search-decoration{appearance:none}textarea.BaseField{block-size:auto;line-height:1.5rem;min-block-size:2rem;padding:calc(var(--field-padding)/2) calc(var(--field-padding) + 1rem) calc(var(--field-padding)/2) var(--field-padding);resize:vertical}textarea.BaseField::-webkit-datetime-edit-text{opacity:.3}textarea.BaseField::-webkit-calendar-picker-indicator{color:var(--global-foreground)}textarea.BaseField:-moz-ui-invalid{box-shadow:none}textarea.BaseField::-webkit-calendar-picker-indicator:hover{background-color:transparent}}
@@ -55,6 +55,14 @@ export declare type TextfieldProps<T = Record<string, unknown>> = BaseFieldProps
55
55
  * Make the textfield full width, filling the available space.
56
56
  */
57
57
  fullWidth?: boolean;
58
+ /**
59
+ * Set a minimum number of rows for the textarea only.
60
+ */
61
+ minRows?: number;
62
+ /**
63
+ * Set a maximum number of rows for the textarea only. The rest of the content will be scrollable.
64
+ */
65
+ maxRows?: number;
58
66
  }> & T;
59
67
  export declare const Textfield: import("react").ForwardRefExoticComponent<Pick<TextfieldProps<Record<string, unknown>>, string> & import("react").RefAttributes<PrimitiveInputType>>;
60
68
  //# sourceMappingURL=textfield.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"textfield.d.ts","sourceRoot":"","sources":["../../../src/components/textfield/textfield.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACZ,MAAM,OAAO,CAAC;AAGf,OAAO,EACuC,WAAW,EACxD,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAa,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAG7E,oBAAY,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC;IACvE;;OAEG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;IACxC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;IAC5D;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,GAAG,CAAC,CAAA;AAEN,eAAO,MAAM,SAAS,sJAuHpB,CAAC"}
1
+ {"version":3,"file":"textfield.d.ts","sourceRoot":"","sources":["../../../src/components/textfield/textfield.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACZ,MAAM,OAAO,CAAC;AAGf,OAAO,EACuC,WAAW,EACxD,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAa,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAG7E,oBAAY,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC;IACvE;;OAEG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;IACxC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;IAC5D;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC,GAAG,CAAC,CAAA;AAEN,eAAO,MAAM,SAAS,sJAyIpB,CAAC"}
@@ -5,7 +5,7 @@ import { useUIDSeed } from 'react-uid';
5
5
  import { IconButton, Stack, Symbol, Text, } from '../..';
6
6
  import { BaseField } from './base-field';
7
7
  import * as styles from './textfield.module.css';
8
- export const Textfield = forwardRef(({ children, className, disabled = false, icon, label, textarea, readOnly, invalid, id, iconPosition = 'right', dimension = 'regular', message, type, style, onChange, fullWidth, ...otherProps }, forwardedRef) => {
8
+ export const Textfield = forwardRef(({ children, className, disabled = false, icon, label, textarea, readOnly, invalid, id, iconPosition = 'right', dimension = 'regular', message, type, style, fullWidth, minRows = 4, maxRows = 6, onChange, ...otherProps }, forwardedRef) => {
9
9
  const [isPasswordVisible, setPasswordVisible] = useState(false);
10
10
  const seedID = useUIDSeed();
11
11
  const isPassword = type === 'password';
@@ -13,6 +13,11 @@ export const Textfield = forwardRef(({ children, className, disabled = false, ic
13
13
  const handlePasswordVisibility = useCallback(() => {
14
14
  setPasswordVisible(visibility => !visibility);
15
15
  }, []);
16
+ const dynamicStyle = {
17
+ '--textarea-min-height': (minRows > 0) ? `${24 * minRows + 16 + 2}px` : 'unset',
18
+ '--textarea-max-height': (maxRows > 0) ? `${24 * maxRows + 16 + 2}px` : 'unset',
19
+ '--textarea-overflow-y': (maxRows > 0) ? 'scroll' : 'unset',
20
+ };
16
21
  const iconSizes = {
17
22
  small: 12,
18
23
  regular: 16,
@@ -29,8 +34,14 @@ export const Textfield = forwardRef(({ children, className, disabled = false, ic
29
34
  disabled,
30
35
  onChange,
31
36
  };
32
- return (_jsxs(Stack, { as: "fieldset", rowGap: 4, className: clsx(styles.Textfield, className), "data-testid": "Textfield", "data-textfield-has-icon": isPassword || Boolean(icon), "data-textfield-icon-position": iconPosition, "data-textfield-dimension": dimension, "data-textfield-invalid": invalid && !disabled, "data-textfield-fullwidth": fullWidth, "aria-disabled": disabled, hAlign: "stretch", vAlign: "start", tabIndex: disabled ? 0 : undefined, style: style, children: [label && _jsx(Text, { as: "label", "aria-disabled": disabled, className: styles.Label, variant: dimension === 'big' ? 'body-1' : 'body-2', htmlFor: fieldID, children: label }), _jsxs("div", { className: styles.FieldContainer, children: [textarea
33
- ? (_jsx(BaseField, { ref: forwardedRef, as: "textarea", id: fieldID, ...commonProps, ...otherProps }))
34
- : (_jsx(BaseField, { className: styles.InputField, id: fieldID, ref: forwardedRef, type: isPasswordVisible ? 'text' : type, spellCheck: isPassword ? false : undefined, ...commonProps, ...otherProps })), isPassword && (_jsx(IconButton, { className: styles.IconButton, dimension: actionSizes[dimension], onClick: handlePasswordVisibility, kind: "flat", "aria-label": "Reveal password", "data-testid": "RevealIcon", icon: isPasswordVisible ? 'eye-slash' : 'eye', disabled: disabled })), !textarea && icon && !isPassword && (_jsx(Symbol, { className: styles.Icon, source: icon, dimension: iconSizes[dimension], "aria-disabled": disabled }))] }), message && _jsx(Text, { as: "label", color: (invalid && !disabled) ? 'danger' : undefined, "aria-disabled": disabled, className: styles.Label, variant: dimension === 'big' ? 'body-2' : 'body-3', children: message })] }));
37
+ return (_jsxs(Stack, { as: "fieldset", rowGap: 4, className: clsx(styles.Textfield, className), "data-testid": "Textfield", "data-textfield-has-icon": isPassword || Boolean(icon), "data-textfield-icon-position": iconPosition, "data-textfield-dimension": dimension, "data-textfield-invalid": invalid && !disabled, "data-textfield-fullwidth": fullWidth, "aria-disabled": disabled, "aria-invalid": invalid && !disabled, hAlign: "stretch", vAlign: "start", tabIndex: disabled ? 0 : undefined, style: style, children: [label && _jsx(Text, { as: "label", "aria-disabled": disabled, className: styles.Label, variant: dimension === 'big' ? 'body-1' : 'body-2', htmlFor: fieldID, children: label }), _jsxs("div", { className: styles.FieldContainer, children: [textarea
38
+ ? (_jsx(BaseField, { ref: forwardedRef, as: "textarea", className: styles.Textarea, style: { ...dynamicStyle }, id: fieldID, ...commonProps, ...otherProps }))
39
+ : (_jsx(BaseField, { className: styles.InputField, id: fieldID, ref: forwardedRef, type: isPasswordVisible ? 'text' : type, spellCheck: isPassword ? false : undefined, ...commonProps, ...otherProps })), isPassword && (_jsx(IconButton, { className: styles.IconButton, dimension: actionSizes[dimension], onClick: handlePasswordVisibility, kind: "flat", "aria-label": "Reveal password", "data-testid": "RevealIcon", icon: isPasswordVisible ? 'eye-slash' : 'eye',
40
+ // eslint-disable-next-line no-nested-ternary
41
+ iconColor: disabled
42
+ ? 'var(--global-disabled-foreground)'
43
+ : invalid
44
+ ? 'var(--highlight-red-foreground)'
45
+ : 'var(--global-foreground)', disabled: disabled })), !textarea && icon && !isPassword && (_jsx(Symbol, { className: styles.Icon, source: icon, dimension: iconSizes[dimension], "aria-disabled": disabled, fill: disabled ? 'var(--global-disabled-foreground)' : 'currentcolor' }))] }), message && _jsx(Text, { as: "label", color: (invalid && !disabled) ? 'danger' : undefined, "aria-disabled": disabled, className: styles.Label, variant: dimension === 'big' ? 'body-2' : 'body-3', children: message })] }));
35
46
  });
36
47
  Textfield.displayName = 'Textfield';
@@ -1 +1 @@
1
- @layer components{.Textfield{appearance:none;padding:0;position:relative}.Textfield[data-textfield-dimension=small]{--field-height:1.500rem;--field-padding:0.33rem;--font-size:0.875rem}.Textfield[data-textfield-dimension=regular]{--field-height:2.25rem;--field-padding:0.875rem;--font-size:0.875rem}.Textfield[data-textfield-dimension=big]{--field-height:3.000rem;--field-padding:1.000rem;--font-size:1rem}.Textfield[data-textfield-fullwidth=true]{inline-size:100%}.FieldContainer{position:relative}.InputField{--factor:4}[data-textfield-has-icon=true][data-textfield-icon-position=right] .InputField{padding:0 calc(var(--field-padding)*var(--factor)) 0 var(--field-padding)}[data-textfield-has-icon=true][data-textfield-icon-position=left] .InputField{padding:0 var(--field-padding) 0 calc(var(--field-padding)*var(--factor))}[data-textfield-dimension*=big] .InputField,[data-textfield-dimension*=regular] .InputField{--factor:3}.Icon{border-radius:.25rem;pointer-events:none;position:absolute;top:50%;transform:translateY(-50%)}[data-textfield-icon-position=left] .Icon{left:var(--field-padding);right:auto}[data-textfield-icon-position=right] .Icon{left:auto;right:var(--field-padding)}.Textfield[data-textfield-invalid=true] .Icon{fill:var(--highlight-red-foreground)}.Icon[aria-disabled=true]{color:var(--global-disabled-foreground);cursor:not-allowed}.InputField:invalid+.Icon{fill:var(--highlight-red-foreground)}label.Label[aria-disabled=true]{color:var(--global-disabled-foreground);cursor:not-allowed}}@layer overrides{.IconButton{--x:25%;outline-offset:-.25em;position:absolute;top:50%;transform:translateY(-50%) translateX(var(--x))}.IconButton[data-button-kind=flat]:is(:hover,:active,:focus){-webkit-backdrop-filter:none;backdrop-filter:none;background-color:transparent}.IconButton[data-button-kind=flat]:is([data-button-disabled=true]){-webkit-backdrop-filter:none;backdrop-filter:none;background-color:unset;block-size:unset;cursor:not-allowed}[data-textfield-icon-position=left] .IconButton{--x:-19%;left:var(--field-padding);right:auto}[data-textfield-icon-position=right] .IconButton{left:auto;right:var(--field-padding)}.Textfield[data-textfield-invalid=true] .IconButton{color:var(--highlight-red-foreground)}}
1
+ @layer components{.Textfield{appearance:none;padding:0;position:relative}.Textfield[data-textfield-dimension=small]{--field-height:1.500rem;--field-padding:0.33rem;--font-size:0.875rem}.Textfield[data-textfield-dimension=regular]{--field-height:2.25rem;--field-padding:0.875rem;--font-size:0.875rem}.Textfield[data-textfield-dimension=big]{--field-height:3.000rem;--field-padding:1.000rem;--font-size:1rem}.Textfield[data-textfield-fullwidth=true]{inline-size:100%}textarea.Textarea{max-height:var(--textarea-max-height);min-height:var(--textarea-min-height);overflow-y:var(--textarea-overflow-y);padding:.5rem 1rem}.FieldContainer{position:relative}.InputField{--factor:4}[data-textfield-has-icon=true][data-textfield-icon-position=right] .InputField{padding:0 calc(var(--field-padding)*var(--factor)) 0 var(--field-padding)}[data-textfield-has-icon=true][data-textfield-icon-position=left] .InputField{padding:0 var(--field-padding) 0 calc(var(--field-padding)*var(--factor))}[data-textfield-dimension*=big] .InputField,[data-textfield-dimension*=regular] .InputField{--factor:3}.Icon{border-radius:.25rem;pointer-events:none;position:absolute;top:50%;transform:translateY(-50%)}[data-textfield-icon-position=left] .Icon{left:var(--field-padding);right:auto}[data-textfield-icon-position=right] .Icon{left:auto;right:var(--field-padding)}.Textfield[data-textfield-invalid=true] .Icon{fill:var(--highlight-red-foreground)}.Icon[aria-disabled=true] svg{color:var(--global-disabled-foreground);cursor:not-allowed}.InputField:invalid+.Icon{fill:var(--highlight-red-foreground)}label.Label[aria-disabled=true]{color:var(--global-disabled-foreground);cursor:not-allowed}}@layer overrides{.IconButton{--x:25%;outline-offset:-.25em;position:absolute;top:50%;transform:translateY(-50%) translateX(var(--x))}.IconButton[data-button-kind=flat]:is(:hover,:active,:focus,[data-button-disabled=true]){-webkit-backdrop-filter:none;backdrop-filter:none;background-color:transparent}.IconButton[aria-disabled=true]{-webkit-backdrop-filter:none;backdrop-filter:none;background-color:unset;block-size:unset;cursor:not-allowed}[data-textfield-icon-position=left] .IconButton{--x:-19%;left:var(--field-padding);right:auto}[data-textfield-icon-position=right] .IconButton{left:auto;right:var(--field-padding)}.Textfield[data-textfield-invalid=true] .IconButton{color:var(--highlight-red-foreground)}}
@@ -1 +1 @@
1
- {"version":3,"file":"textfield.stories.d.ts","sourceRoot":"","sources":["../../../src/components/textfield/textfield.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,SAAS,CAoC1C,CAAC;AAEF,eAAe,KAAK,CAAC;AA2BrB,eAAO,MAAM,MAAM,+LAA0B,CAAC;AAc9C,eAAO,MAAM,KAAK,+LAA4B,CAAC;AAgB/C,eAAO,MAAM,QAAQ,+LAA4B,CAAC;AAalD,eAAO,MAAM,QAAQ,+LAA0B,CAAC"}
1
+ {"version":3,"file":"textfield.stories.d.ts","sourceRoot":"","sources":["../../../src/components/textfield/textfield.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,SAAS,CAsC1C,CAAC;AAEF,eAAe,KAAK,CAAC;AA4BrB,eAAO,MAAM,MAAM,+LAA0B,CAAC;AAc9C,eAAO,MAAM,KAAK,+LAA4B,CAAC;AAsB/C,eAAO,MAAM,QAAQ,+LAA4B,CAAC;AAelD,eAAO,MAAM,QAAQ,+LAA0B,CAAC"}
@@ -8,6 +8,8 @@ const story = {
8
8
  dimension: 'regular',
9
9
  readOnly: false,
10
10
  defaultValue: 'Sample value',
11
+ minRows: 0,
12
+ maxRows: 0,
11
13
  },
12
14
  argTypes: {
13
15
  onChange: {
@@ -40,7 +42,7 @@ const story = {
40
42
  };
41
43
  export default story;
42
44
  const SingleTemplate = args => (_jsxs(Stack, { rowGap: 24, children: [_jsx(Textfield, { ...args, size: 4, placeholder: "Placeholder", message: "" }), _jsx(Textfield, { ...args, size: 4, placeholder: "Placeholder" }), _jsx(Textfield, { ...args, type: "password", label: "Password", defaultValue: "123123kl\u00F2asj", placeholder: "Placeholder" })] }));
43
- const MultipleTemplate = args => (_jsxs(Stack, { rowGap: 24, children: [_jsx(Textfield, { ...args, label: "Filled", defaultValue: "Sample value" }), _jsx(Textfield, { ...args, label: "Filled read only", defaultValue: "Sample value", readOnly: true }), _jsx(Textfield, { ...args, label: "Empty disbled", placeholder: "Placeholder", disabled: true }), _jsx(Textfield, { ...args, label: "Filled disabled", defaultValue: "Sample value", disabled: true }), _jsx(Textfield, { ...args, type: "password", label: "Type password", defaultValue: "912435jh345" }), _jsx(Textfield, { ...args, type: "number", label: "Type number", defaultValue: 100 }), _jsx(Textfield, { ...args, type: "search", label: "Type search" }), _jsx(Textfield, { ...args, type: "date", label: "Type date" }), _jsx(Textfield, { ...args, type: "time", label: "Type time" }), _jsx(Textfield, { ...args, type: "month", label: "Type month" }), _jsx(Textfield, { ...args, type: "week", label: "Type week" }), _jsx(Textfield, { ...args, type: "datetime-local", label: "Type datetime-local" })] }));
45
+ const MultipleTemplate = args => (_jsxs(Stack, { rowGap: 24, children: [_jsx(Textfield, { ...args, label: "Filled", defaultValue: "Sample value" }), _jsx(Textfield, { ...args, label: "Filled read only", defaultValue: "Sample value", readOnly: true }), _jsx(Textfield, { ...args, label: "With optional placeholder", defaultValue: "", placeholder: "Placeholder" }), _jsx(Textfield, { ...args, label: "Empty disbled", placeholder: "Placeholder", disabled: true }), _jsx(Textfield, { ...args, label: "Filled disabled", defaultValue: "Sample value", disabled: true }), _jsx(Textfield, { ...args, type: "password", label: "Type password", defaultValue: "912435jh345" }), _jsx(Textfield, { ...args, type: "number", label: "Type number", defaultValue: 100 }), _jsx(Textfield, { ...args, type: "search", label: "Type search" }), _jsx(Textfield, { ...args, type: "date", label: "Type date" }), _jsx(Textfield, { ...args, type: "time", label: "Type time" }), _jsx(Textfield, { ...args, type: "month", label: "Type month" }), _jsx(Textfield, { ...args, type: "week", label: "Type week" }), _jsx(Textfield, { ...args, type: "datetime-local", label: "Type datetime-local" })] }));
44
46
  export const Single = SingleTemplate.bind({});
45
47
  Single.args = {
46
48
  disabled: false,
@@ -65,11 +67,13 @@ Types.argTypes = {
65
67
  },
66
68
  },
67
69
  };
68
- const TextareaTemplate = args => (_jsx(Textfield, { ...args, defaultValue: "123123kl\u00F2asj", placeholder: "Placeholder" }));
70
+ const TextareaTemplate = args => (_jsx(Textfield, { ...args, defaultValue: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas aut, enim tempore necessitatibus maiores temporibus? Cumque nulla harum pariatur nesciunt repellat similique. Velit, totam qui.", placeholder: "Placeholder", label: "Label", message: "Sample hint text" }));
69
71
  export const Textarea = TextareaTemplate.bind({});
70
72
  Textarea.args = {
71
73
  disabled: false,
72
74
  textarea: true,
75
+ minRows: 4,
76
+ maxRows: 6,
73
77
  };
74
78
  Textarea.argTypes = {
75
79
  textarea: {
@@ -1 +1 @@
1
- @layer components{.Tooltip{display:contents}.Balloon{word-wrap:break-word;background-color:#31363f;border-radius:.25rem;max-inline-size:var(--max-w);padding:.5rem 1rem;position:relative;z-index:5}.Balloon,.Balloon p{font-size:.875rem}.Balloon[data-popper-reference-hidden=true]{pointer-events:none;visibility:hidden}.Arrow:before{background-color:#31363f;block-size:12px;content:"";inline-size:12px;position:absolute;transform:rotate(45deg);visibility:visible}.Balloon[data-popper-reference-hidden=true] .Arrow{pointer-events:none;visibility:hidden}.Balloon[data-popper-placement^=top] .Arrow{bottom:6px}.Balloon[data-popper-placement^=top] .Arrow:before{transform:translateX(-50%) translateY(-2px) rotate(45deg)}.Balloon[data-popper-placement^=left] .Arrow{right:6px}.Balloon[data-popper-placement^=left] .Arrow:before{transform:translateX(-2px) translateY(-50%) rotate(45deg)}.Balloon[data-popper-placement^=bottom] .Arrow{top:-6px}.Balloon[data-popper-placement^=bottom] .Arrow:before{transform:translateX(-50%) translateY(2px) rotate(45deg)}.Balloon[data-popper-placement^=right] .Arrow{left:-6px}.Balloon[data-popper-placement^=right] .Arrow:before{transform:translateX(2px) translateY(-50%) rotate(45deg)}}
1
+ @layer components{.Tooltip{display:contents}.Balloon{word-wrap:break-word;background-color:#31363f;border-radius:.25rem;max-inline-size:var(--max-w);padding:.5rem 1rem;position:relative;z-index:5}.Balloon,.Balloon p{font-size:.875rem}.Balloon[data-popper-reference-hidden=true]{pointer-events:none;visibility:hidden}.Arrow:before{background-color:#31363f;block-size:12px;content:"";inline-size:12px;position:absolute;transform:rotate(45deg);visibility:visible}.Balloon[data-popper-reference-hidden=true] .Arrow{pointer-events:none;visibility:hidden}.Balloon[data-popper-placement^=top] .Arrow{bottom:6px}.Balloon[data-popper-placement^=top] .Arrow:before{transform:translateX(-50%) translateY(0) rotate(45deg)}.Balloon[data-popper-placement^=left] .Arrow{right:6px}.Balloon[data-popper-placement^=left] .Arrow:before{transform:translateX(-2px) translateY(-50%) rotate(45deg)}.Balloon[data-popper-placement^=bottom] .Arrow{top:-6px}.Balloon[data-popper-placement^=bottom] .Arrow:before{transform:translateX(-50%) translateY(2px) rotate(45deg)}.Balloon[data-popper-placement^=right] .Arrow{left:-6px}.Balloon[data-popper-placement^=right] .Arrow:before{transform:translateX(1px) translateY(-50%) rotate(45deg)}}
@@ -1 +1 @@
1
- {"version":3,"file":"shell.stories.d.ts","sourceRoot":"","sources":["../../src/examples/shell.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQjE,OAAO,EAGL,SAAS,EAOV,MAAM,cAAc,CAAC;AAItB,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,SAAS,CAG1C,CAAC;AAEF,eAAe,KAAK,CAAC;AAqJrB,eAAO,MAAM,KAAK,kHAAoB,CAAC"}
1
+ {"version":3,"file":"shell.stories.d.ts","sourceRoot":"","sources":["../../src/examples/shell.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQjE,OAAO,EAEL,SAAS,EAOV,MAAM,cAAc,CAAC;AAItB,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,SAAS,CAG1C,CAAC;AAEF,eAAe,KAAK,CAAC;AAqKrB,eAAO,MAAM,KAAK,kHAAoB,CAAC"}
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import clsx from 'clsx';
3
3
  import { useEffect, useMemo, useRef, useState, } from 'react';
4
4
  import { useUIDSeed } from 'react-uid';
5
- import { Button, Card, Container, Disclosure, Grid, IconButton, Menu, Snackbar, Stack, Text, useBreakpoints, useBreakpointsConfig, useSSR, } from '..';
5
+ import { Button, Container, Disclosure, Grid, IconButton, Menu, ProductCard, Snackbar, Stack, Text, useBreakpoints, useBreakpointsConfig, useSSR, } from '..';
6
6
  import * as style from './shell.module.css';
7
7
  const story = {
8
8
  title: 'Examples/Wireframe',
@@ -35,6 +35,6 @@ const Template = () => {
35
35
  }, [isBrowser]);
36
36
  return (_jsx(Container, { dimension: "full", padding: false, className: style.MainContainer, children: _jsxs(Stack, { direction: "row", children: [_jsxs(Stack, { id: "LeftMenu", rowGap: 16, className: style.LeftMenu, "data-is-open": isLeftOpen, children: [_jsx("div", { className: style.LeftMenuInner, "data-is-open": isLeftOpen }), isLeftOpen
37
37
  ? (_jsx("div", { children: linkIcons.map((e, i) => (_jsx(Menu.Item, { disabled: true, value: `${e}`, icon: linkIcons[i], children: e }, seed(`linkMenu${i}`)))) }))
38
- : (_jsx(Stack, { inline: true, hAlign: "center", rowGap: 8, children: linkIcons.map((e, i) => (_jsx(IconButton, { disabled: true, icon: linkIcons[i], kind: "flat" }, `${e} ${seed(`icons${i}`)}`))) }))] }), _jsxs(Stack, { children: [_jsxs(Stack, { id: "MainMenu", direction: "row", vAlign: "center", hAlign: "space-between", columnGap: 16, className: style.MainMenu, children: [_jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsLeftOpen(!isLeftOpen), children: "Menu" }) }), _jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsRightOpen(!isRightOpen), children: "Filters" }) })] }), _jsx(Container, { ref: ref, dimension: containerValue.dimension, className: clsx(style.Container, 'ContainerEx'), children: _jsxs(Stack, { rowGap: 32, vPadding: 32, children: [_jsxs(Snackbar, { title: "Product Card Container", children: [_jsx(Text, { children: `Window Width: ${size}px - Breakpoints Match: ${matches.toUpperCase()}` }), _jsx(Text, { children: `Container Width: ${containerSize}px - Grid Columns: ${containerValue.col} - Grid Gutter: ${containerValue.gutter}px` }), _jsx(Text, { children: `useBreakpointsConfig.value: ${JSON.stringify(containerValue)} - useBreakpointsConfig.matches: ${containerMatches.toUpperCase()}` })] }), _jsx(Grid, { colMinWidth: "1rem", columns: containerValue.col, rowGap: containerValue.gutter, columnGap: containerValue.gutter, filling: false, children: Array(12).fill('Card').map((e, i) => (_jsx(Grid.Item, { children: _jsx(Card, { bordered: true, style: { height: '500px' }, children: _jsx(Stack, { hAlign: "center", children: _jsx(Text, { variant: "body-2", children: `${e} ${i + 1}` }) }) }) }, seed(`cards${i}`)))) })] }) })] }), _jsxs(Stack, { id: "RightMenu", className: style.RightMenu, "data-is-open": isRightOpen, children: [_jsx("div", { className: style.RightMenuInner }), _jsx("div", { className: style.Filter, children: Array(10).fill('Filter').map((e, i) => (_jsxs(Disclosure, { summary: `${e} ${String.fromCharCode(i + 65)}`, children: [_jsx(Menu.Item, { value: "1", subtext: "Hint Text", children: "Menu Item 1" }), _jsx(Menu.Item, { value: "2", subtext: "Hint Text", children: "Menu Item 2" }), _jsx(Menu.Item, { value: "3", subtext: "Hint Text", children: "Menu Item 3" }), _jsx(Menu.Item, { value: "4", subtext: "Hint Text", children: "Menu Item 4" })] }, seed(`filters${i}`)))) })] })] }) }));
38
+ : (_jsx(Stack, { inline: true, hAlign: "center", rowGap: 8, children: linkIcons.map((e, i) => (_jsx(IconButton, { disabled: true, icon: linkIcons[i], kind: "flat" }, `${e} ${seed(`icons${i}`)}`))) }))] }), _jsxs(Stack, { children: [_jsxs(Stack, { id: "MainMenu", direction: "row", vAlign: "center", hAlign: "space-between", columnGap: 16, className: style.MainMenu, children: [_jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsLeftOpen(!isLeftOpen), children: "Menu" }) }), _jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsRightOpen(!isRightOpen), children: "Filters" }) })] }), _jsx(Container, { ref: ref, dimension: containerValue.dimension, className: clsx(style.Container, 'ContainerEx'), children: _jsxs(Stack, { rowGap: 32, vPadding: 32, children: [_jsxs(Snackbar, { title: "Product Card Container", children: [_jsx(Text, { as: "span", variant: "body-2", children: `Window Width: ${size}px - Breakpoints Match: ${matches.toUpperCase()}` }), _jsx(Text, { as: "span", variant: "body-2", children: `Container Width: ${containerSize}px - Grid Columns: ${containerValue.col} - Grid Gutter: ${containerValue.gutter}px` }), _jsx(Text, { as: "span", variant: "body-2", children: `useBreakpointsConfig.value: ${JSON.stringify(containerValue)} - useBreakpointsConfig.matches: ${containerMatches.toUpperCase()}` })] }), _jsx(Grid, { colMinWidth: "1rem", columns: containerValue.col, rowGap: containerValue.gutter, columnGap: containerValue.gutter, filling: false, children: Array(12).fill('Card').map((e, i) => (_jsx(Grid.Item, { children: _jsx(ProductCard, { source: ['https://storage.googleapis.com/wonderflow-product-images/KITCHENAID%20CLASSIC%20SERIES.png'], subtitle: "brand name", title: `Product-${e} ${i + 1}`, sentiment: 0.51, rating: 4.51, feedbackCount: 3251, footer: "01 Aug 2023", menuActions: (_jsx(Menu, { children: _jsx(Menu.Item, { autoFocus: true, icon: "news", value: "1", children: "Stats" }) })), highlightOnHover: true }) }, seed(`cards${i}`)))) })] }) })] }), _jsxs(Stack, { id: "RightMenu", className: style.RightMenu, "data-is-open": isRightOpen, children: [_jsx("div", { className: style.RightMenuInner }), _jsx("div", { className: style.Filter, children: Array(10).fill('Filter').map((e, i) => (_jsxs(Disclosure, { summary: `${e} ${String.fromCharCode(i + 65)}`, children: [_jsx(Menu.Item, { value: "1", subtext: "Hint Text", children: "Menu Item 1" }), _jsx(Menu.Item, { value: "2", subtext: "Hint Text", children: "Menu Item 2" }), _jsx(Menu.Item, { value: "3", subtext: "Hint Text", children: "Menu Item 3" }), _jsx(Menu.Item, { value: "4", subtext: "Hint Text", children: "Menu Item 4" })] }, seed(`filters${i}`)))) })] })] }) }));
39
39
  };
40
40
  export const Shell = Template.bind({});
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from './components';
2
2
  export * from './hooks';
3
3
  export * from './providers';
4
4
  export * from './types';
5
+ export * from './utils';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -17,3 +17,4 @@ export * from './components';
17
17
  export * from './hooks';
18
18
  export * from './providers';
19
19
  export * from './types';
20
+ export * from './utils';
@@ -1,2 +1,2 @@
1
- export declare const isBrowser: () => false | HTMLElement;
1
+ export declare const isBrowser: () => boolean;
2
2
  //# sourceMappingURL=browser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/utils/browser.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,SAAS,2BAEiB,CAAC"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/utils/browser.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,SAAS,eAEiB,CAAC"}
@@ -13,6 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export const isBrowser = () => (typeof window !== 'undefined'
16
+ export const isBrowser = () => !!(typeof window !== 'undefined'
17
17
  && window.document
18
18
  && window.document.documentElement);
@@ -1,7 +1,7 @@
1
1
  import { isBrowser } from './browser';
2
2
  describe('isBrowser()', () => {
3
3
  it('should test browser true', () => {
4
- const b = isBrowser();
5
- expect(b).toBeTruthy();
4
+ const isB = isBrowser();
5
+ expect(isB).toBeTruthy();
6
6
  });
7
7
  });
@@ -0,0 +1,16 @@
1
+ import { Currency } from '../components/product-card/product-card-kpis/product-card-kpis';
2
+ export declare const getCurrency: (currency?: Currency) => "" | "€" | "$" | "£" | "¥";
3
+ export declare const formatPriceRangeValues: (p1?: number, p2?: number, option?: {
4
+ currency?: Currency;
5
+ decimals: number;
6
+ }) => string | undefined;
7
+ export declare const clampValue: (value: number, minRange?: number, maxRange?: number) => number;
8
+ export declare const formatKpiValue: (value?: number, option?: {
9
+ decimal: number;
10
+ minRange?: number;
11
+ maxRange?: number;
12
+ cap?: number;
13
+ }) => string;
14
+ export declare const isValueOverCap: (value?: number, cap?: number) => boolean;
15
+ export declare const isGreaterThan: (threashold: number, value?: number) => boolean;
16
+ //# sourceMappingURL=formatting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,QAAQ,EAAE,MAAM,gEAAgE,CAAC;AAE1F,eAAO,MAAM,WAAW,cAAe,QAAQ,+BAc9C,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAC5B,MAAM,OACN,MAAM,WACH;IACN,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,uBAkBF,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,MAAM,aAAa,MAAM,aAAa,MAAM,WAU7E,CAAC;AAEF,eAAO,MAAM,cAAc,WACjB,MAAM,WACN;IACN,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,WAqBF,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,MAAM,QAAQ,MAAM,YAAuF,CAAC;AAEnJ,eAAO,MAAM,aAAa,eAAgB,MAAM,UAAU,MAAM,YAAsD,CAAC"}
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright 2023 Wonderflow Design Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export const getCurrency = (currency) => {
17
+ switch (currency) {
18
+ case 'EUR':
19
+ return '€';
20
+ case 'USD':
21
+ return '$';
22
+ case 'GBP':
23
+ return '£';
24
+ case 'JPY':
25
+ case 'CNY':
26
+ return '¥';
27
+ default:
28
+ return '';
29
+ }
30
+ };
31
+ export const formatPriceRangeValues = (p1, p2, option = { currency: 'EUR', decimals: 2 }) => {
32
+ const { currency, decimals: decimal } = option;
33
+ const isP1Number = typeof p1 === 'number';
34
+ const isP2Number = typeof p2 === 'number';
35
+ if (isP1Number && isP2Number) {
36
+ const min = Math.min(p1, p2).toFixed(decimal);
37
+ const max = Math.max(p1, p2).toFixed(decimal);
38
+ return (`${min} - ${max} ${getCurrency(currency)}`).trim();
39
+ }
40
+ if (isP1Number || isP2Number) {
41
+ const val = isP1Number ? p1.toFixed(decimal) : p2.toFixed(decimal);
42
+ return (`${val} ${getCurrency(currency)}`).trim();
43
+ }
44
+ return undefined;
45
+ };
46
+ export const clampValue = (value, minRange, maxRange) => {
47
+ const isMin = typeof minRange === 'number';
48
+ const isMax = typeof maxRange === 'number';
49
+ let newMin = value;
50
+ let newMax = value;
51
+ if (isMin)
52
+ newMin = minRange;
53
+ if (isMax)
54
+ newMax = maxRange;
55
+ if (value < newMin)
56
+ return newMin;
57
+ if (value > newMax)
58
+ return newMax;
59
+ return value;
60
+ };
61
+ export const formatKpiValue = (value, option = { decimal: 0, minRange: 0 }) => {
62
+ const { decimal, minRange, maxRange, cap, } = option;
63
+ const hasValue = typeof value === 'number';
64
+ const d = typeof decimal === 'number' && decimal > 0 ? decimal : 0;
65
+ if (hasValue) {
66
+ const res = clampValue(value, minRange, maxRange).toFixed(d);
67
+ if (typeof cap === 'number' && cap > 0) {
68
+ const c = clampValue(cap, minRange, maxRange).toFixed(d);
69
+ return `${res} / ${c}`;
70
+ }
71
+ return res;
72
+ }
73
+ return '';
74
+ };
75
+ export const isValueOverCap = (value, cap) => !!(typeof value === 'number' && typeof cap === 'number' && value > cap && cap > 0);
76
+ export const isGreaterThan = (threashold, value) => (typeof value === 'number' && value > threashold);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=formatting.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.test.d.ts","sourceRoot":"","sources":["../../src/utils/formatting.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,151 @@
1
+ import { clampValue, formatKpiValue, formatPriceRangeValues, getCurrency, isGreaterThan, isValueOverCap, } from './formatting';
2
+ describe('formatPriceRangeValues()', () => {
3
+ it('should return both price values', () => {
4
+ const res = formatPriceRangeValues(10, 20);
5
+ expect(res).toBe('10.00 - 20.00 €');
6
+ });
7
+ it('should return both price values with currency $ and w/o decimal', () => {
8
+ const res = formatPriceRangeValues(10, 20, { currency: 'USD', decimals: 0 });
9
+ expect(res).toBe('10 - 20 $');
10
+ });
11
+ it('should return both price values w/o currency', () => {
12
+ const res = formatPriceRangeValues(10, 20, { currency: undefined, decimals: 0 });
13
+ expect(res).toBe('10 - 20');
14
+ });
15
+ it('should return only the first value', () => {
16
+ const res = formatPriceRangeValues(10);
17
+ expect(res).toBe('10.00 €');
18
+ });
19
+ it('should return only the second value', () => {
20
+ const res = formatPriceRangeValues(undefined, 20);
21
+ expect(res).toBe('20.00 €');
22
+ });
23
+ it('should return undefined', () => {
24
+ const res = formatPriceRangeValues(undefined, undefined);
25
+ expect(res).toBeFalsy();
26
+ });
27
+ });
28
+ describe('clampValue()', () => {
29
+ it('should clamp value correctly', () => {
30
+ const val = 10;
31
+ const min = 0;
32
+ const max = 11;
33
+ const test = 10;
34
+ const res = clampValue(val, min, max);
35
+ expect(res).toBe(test);
36
+ });
37
+ it('should clamp value correctly w/o max', () => {
38
+ const val = 10;
39
+ const min = 0;
40
+ const max = undefined;
41
+ const test = 10;
42
+ const res = clampValue(val, min, max);
43
+ expect(res).toBe(test);
44
+ });
45
+ it('should clamp value correctly w/o min', () => {
46
+ const val = 10;
47
+ const min = undefined;
48
+ const max = 10;
49
+ const test = 10;
50
+ const res = clampValue(val, min, max);
51
+ expect(res).toBe(test);
52
+ });
53
+ it('should clamp negative value correctly w/o max', () => {
54
+ const val = -10;
55
+ const min = 0;
56
+ const max = undefined;
57
+ const test = 0;
58
+ const res = clampValue(val, min, max);
59
+ expect(res).toBe(test);
60
+ });
61
+ });
62
+ describe('formatKpiValue()', () => {
63
+ it('should return a value with 2 decimals" ', () => {
64
+ const res = formatKpiValue(10, { decimal: 2 });
65
+ expect(res).toBe('10.00');
66
+ });
67
+ it('should return a value w/o decimals', () => {
68
+ const res = formatKpiValue(10);
69
+ expect(res).toBe('10');
70
+ });
71
+ it('should return a negative value with 2 decimals', () => {
72
+ const res = formatKpiValue(-10, { decimal: 2 });
73
+ expect(res).toBe('-10.00');
74
+ });
75
+ it('should return a value with 1 decimals low clamped', () => {
76
+ const res = formatKpiValue(10, { decimal: 1, minRange: 11 });
77
+ expect(res).toBe('11.0');
78
+ });
79
+ it('should return a value with 1 decimals high clamped', () => {
80
+ const res = formatKpiValue(10, { decimal: 1, maxRange: 9 });
81
+ expect(res).toBe('9.0');
82
+ });
83
+ it('should return a value with 1 decimals high clamped', () => {
84
+ const res = formatKpiValue(10, { decimal: 1, minRange: 9 });
85
+ expect(res).toBe('10.0');
86
+ });
87
+ it('should return an empty string passing nullish value', () => {
88
+ const res = formatKpiValue(undefined, { decimal: 2 });
89
+ expect(res).toBe('');
90
+ });
91
+ it('should return correct format with cap', () => {
92
+ const res = formatKpiValue(10, { decimal: 0, cap: 100 });
93
+ expect(res).toBe('10 / 100');
94
+ });
95
+ });
96
+ describe('isValueOverCap()', () => {
97
+ it('should return true when value > cap', () => {
98
+ const val = 10;
99
+ const cap = 9;
100
+ const isOver = isValueOverCap(val, cap);
101
+ expect(isOver).toBeTruthy();
102
+ });
103
+ it('should return true when value < cap', () => {
104
+ const val = 10;
105
+ const cap = 11;
106
+ const isOver = isValueOverCap(val, cap);
107
+ expect(isOver).not.toBeTruthy();
108
+ });
109
+ it('should return false when cap = 0', () => {
110
+ const val = 10;
111
+ const cap = 0;
112
+ const isOver = isValueOverCap(val, cap);
113
+ expect(isOver).not.toBeTruthy();
114
+ });
115
+ });
116
+ describe('isGreaterThan()', () => {
117
+ it('should return true when value > threashold', () => {
118
+ const v = 10;
119
+ const t = 5;
120
+ const isGreater = isGreaterThan(t, v);
121
+ expect(isGreater).toBeTruthy();
122
+ });
123
+ it('should return false when value < threashold', () => {
124
+ const v = 10;
125
+ const t = 15;
126
+ const isGreater = isGreaterThan(t, v);
127
+ expect(isGreater).not.toBeTruthy();
128
+ });
129
+ it('should return false when value = undefined', () => {
130
+ const v = undefined;
131
+ const t = 15;
132
+ const isGreater = isGreaterThan(t, v);
133
+ expect(isGreater).not.toBeTruthy();
134
+ });
135
+ });
136
+ describe('getCurrency()', () => {
137
+ const tests = [
138
+ { code: 'EUR', out: '€' },
139
+ { code: 'USD', out: '$' },
140
+ { code: 'GBP', out: '£' },
141
+ { code: 'JPY', out: '¥' },
142
+ { code: 'CNY', out: '¥' },
143
+ { code: undefined, out: '' },
144
+ ];
145
+ tests.map(t => (it(`should return ${t.out}`, () => {
146
+ const input = t.code;
147
+ const output = getCurrency(input);
148
+ const test = t.out;
149
+ expect(output).toBe(test);
150
+ })));
151
+ });
@@ -0,0 +1,5 @@
1
+ export { isBrowser } from './browser';
2
+ export { cssRelativeUnitsToPixel } from './conversions';
3
+ export { clampValue, formatKpiValue, formatPriceRangeValues, isGreaterThan, isValueOverCap, } from './formatting';
4
+ export { getCurrentTheme, getPrefersColorScheme } from './themes';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACL,UAAU,EAAE,cAAc,EAAE,sBAAsB,EAAE,aAAa,EACjE,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2022-2023 Wonderflow Design Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export { isBrowser } from './browser';
17
+ export { cssRelativeUnitsToPixel } from './conversions';
18
+ export { clampValue, formatKpiValue, formatPriceRangeValues, isGreaterThan, isValueOverCap, } from './formatting';
19
+ export { getCurrentTheme, getPrefersColorScheme } from './themes';