@moda/om 21.0.0-next.1 → 21.0.1

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 (103) hide show
  1. package/README.md +0 -1
  2. package/dist/index.cjs.js +2194 -1983
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.esm.js +2193 -1982
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/src/components/Checkbox/Checkbox.d.ts +1 -1
  7. package/dist/src/components/Clickable/Clickable.d.ts +2 -7
  8. package/dist/src/components/Field/Field.d.ts +1 -1
  9. package/dist/src/components/NavigationPreventer/NavigationPreventer.d.ts +2 -1
  10. package/dist/src/components/PasswordInput/PasswordInput.d.ts +1 -1
  11. package/dist/src/components/Popover/Popover.d.ts +1 -1
  12. package/dist/src/components/PromoBanner/PromoBanner.d.ts +1 -1
  13. package/dist/src/components/RadioButton/RadioButton.d.ts +1 -1
  14. package/dist/src/components/Select/useSelect.d.ts +3 -3
  15. package/dist/src/components/Tabs/Tab.d.ts +1 -1
  16. package/dist/src/components/Text/Text.d.ts +2 -2
  17. package/dist/src/hooks/useClickOutside.d.ts +1 -1
  18. package/dist/src/index.d.ts +10 -1
  19. package/dist/src/utilities/States/State.d.ts +6 -7
  20. package/dist/src/utilities/States/StateProps.d.ts +7 -0
  21. package/dist/src/utilities/States/States.d.ts +6 -7
  22. package/dist/src/utilities/States/Styles.d.ts +14 -0
  23. package/dist/src/utilities/States/index.d.ts +1 -0
  24. package/dist/src/utilities/index.d.ts +7 -0
  25. package/dist/src/utilities/isEmpty.d.ts +1 -0
  26. package/dist/src/utilities/isRenderProps.d.ts +5 -0
  27. package/dist/src/utilities/stringifyProps.d.ts +1 -0
  28. package/dist/src/utilities/truncate.d.ts +1 -0
  29. package/dist/styles.css +1 -1
  30. package/package.json +71 -69
  31. package/src/components/AspectRatioBox/AspectRatioBox.stories.tsx +1 -1
  32. package/src/components/Badge/Badge.stories.tsx +1 -1
  33. package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +1 -1
  34. package/src/components/Breadcrumbs/Breadcrumbs.tsx +2 -2
  35. package/src/components/Breakpoint/Breakpoint.stories.tsx +3 -6
  36. package/src/components/Button/Button.stories.tsx +10 -7
  37. package/src/components/Checkbox/Checkbox.stories.tsx +1 -1
  38. package/src/components/Checkbox/Checkbox.tsx +1 -1
  39. package/src/components/Clickable/Clickable.stories.tsx +7 -4
  40. package/src/components/Clickable/Clickable.tsx +3 -6
  41. package/src/components/ColorSwatch/ColorSwatch.stories.tsx +1 -1
  42. package/src/components/ControlLink/ControlLink.stories.tsx +12 -7
  43. package/src/components/CreditCardNumberInput/CreditCardNumberInput.stories.tsx +1 -1
  44. package/src/components/CreditCardNumberInput/CreditCardNumberInput.test.tsx +3 -6
  45. package/src/components/CreditCardNumberInput/CreditCardNumberInput.tsx +5 -13
  46. package/src/components/DefinitionList/DefinitionList.stories.tsx +1 -1
  47. package/src/components/Divider/Divider.stories.tsx +1 -1
  48. package/src/components/Expandable/Expandable.stories.tsx +1 -1
  49. package/src/components/Field/Field.stories.tsx +1 -1
  50. package/src/components/Field/Field.tsx +1 -1
  51. package/src/components/Label/Label.stories.tsx +1 -1
  52. package/src/components/LoadingItemsLavenderBlue/LoadingItems.stories.tsx +1 -1
  53. package/src/components/LoadingItemsPinkGreen/LoadingItems.stories.tsx +1 -1
  54. package/src/components/LoadingShapes/LoadingShapes.stories.tsx +1 -1
  55. package/src/components/LoadingShapesLavenderBlue/LoadingShapesLavenderBlue.stories.tsx +1 -1
  56. package/src/components/LoadingShapesPinkGreen/LoadingShapesPinkGreen.stories.tsx +1 -1
  57. package/src/components/NavigationPreventer/NavigationPreventer.tsx +5 -5
  58. package/src/components/Overlay/Overlay.stories.tsx +1 -1
  59. package/src/components/PasswordInput/PasswordInput.stories.tsx +1 -1
  60. package/src/components/Popover/Popover.stories.tsx +1 -1
  61. package/src/components/Popover/Popover.tsx +1 -1
  62. package/src/components/PromoBanner/PromoBanner.stories.tsx +1 -1
  63. package/src/components/PromoBanner/PromoBanner.tsx +1 -1
  64. package/src/components/RadioButton/RadioButton.stories.tsx +1 -1
  65. package/src/components/RadioButton/RadioButton.tsx +1 -1
  66. package/src/components/SearchInput/SearchInput.stories.tsx +1 -1
  67. package/src/components/Select/Select.stories.tsx +2 -3
  68. package/src/components/Select/Select.test.tsx +5 -5
  69. package/src/components/SelectableButton/SelectableButton.stories.tsx +1 -1
  70. package/src/components/Shape/Shape.stories.tsx +1 -1
  71. package/src/components/Stack/Stack.stories.tsx +1 -1
  72. package/src/components/Tabs/Tab.tsx +1 -1
  73. package/src/components/Tabs/Tabs.stories.tsx +1 -1
  74. package/src/components/Tag/Tag.stories.tsx +1 -1
  75. package/src/components/Text/Text.scss +1 -1
  76. package/src/components/Text/Text.stories.tsx +1 -1
  77. package/src/components/Text/Text.tsx +2 -2
  78. package/src/components/TextInput/TextInput.stories.tsx +1 -1
  79. package/src/components/Textarea/Textarea.stories.tsx +1 -1
  80. package/src/components/Toast/Toast.stories.tsx +1 -1
  81. package/src/components/VerticalDivider/VerticalDivider.stories.tsx +1 -1
  82. package/src/hooks/useClickOutside.ts +4 -1
  83. package/src/index.scss +0 -1
  84. package/src/index.ts +2 -0
  85. package/src/utilities/States/State.tsx +13 -13
  86. package/src/utilities/States/StateProps.tsx +28 -0
  87. package/src/utilities/States/States.tsx +9 -11
  88. package/src/utilities/States/Styles.tsx +43 -0
  89. package/src/utilities/States/index.ts +1 -0
  90. package/src/utilities/index.ts +7 -0
  91. package/src/utilities/isEmpty.ts +1 -0
  92. package/src/utilities/isRenderProps.ts +9 -0
  93. package/src/utilities/{States/stringifyProps.tsx → stringifyProps.ts} +2 -7
  94. package/src/utilities/truncate.ts +5 -0
  95. package/dist/src/utilities/States/StatesProps.d.ts +0 -8
  96. package/dist/src/utilities/States/isRenderProps.d.ts +0 -4
  97. package/dist/src/utilities/States/stringifyProps.d.ts +0 -1
  98. package/src/functions/_functions.scss +0 -0
  99. package/src/utilities/States/State.scss +0 -11
  100. package/src/utilities/States/States.scss +0 -5
  101. package/src/utilities/States/StatesProps.scss +0 -24
  102. package/src/utilities/States/StatesProps.tsx +0 -31
  103. package/src/utilities/States/isRenderProps.ts +0 -7
@@ -1,4 +1,4 @@
1
- import React, { useState, useCallback, useEffect, useRef, ReactNode } from 'react';
1
+ import React, { useState, useCallback, useEffect, useRef, ReactNode, JSX } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import './Popover.scss';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { States } from 'storybook-states';
2
+ import { States } from '../../utilities';
3
3
  import { PromoBanner, PromoBannerProps } from './PromoBanner';
4
4
 
5
5
  export default { title: 'Components/PromoBanner' };
@@ -1,4 +1,4 @@
1
- import React, { Children, cloneElement } from 'react';
1
+ import React, { Children, cloneElement, JSX } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { Constrain } from '../Constrain';
4
4
  import './PromoBanner.scss';
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react';
2
- import { States } from 'storybook-states';
2
+ import { States } from '../../utilities';
3
3
  import { Text } from '../Text';
4
4
  import { Stack } from '../Stack';
5
5
  import { RadioButton, RadioButtonProps } from './RadioButton';
@@ -1,4 +1,4 @@
1
- import React, { useRef } from 'react';
1
+ import React, { JSX, useRef } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import './RadioButton.scss';
4
4
 
@@ -1,6 +1,6 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
- import { States } from 'storybook-states';
3
+ import { States } from '../../utilities';
4
4
  import { Text } from '../Text';
5
5
  import { SearchInput, SearchInputProps } from './SearchInput';
6
6
 
@@ -1,7 +1,6 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useState, useCallback } from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
- import { States } from 'storybook-states';
4
- import { useCallback } from 'react';
3
+ import { States } from '../../utilities';
5
4
  import { Input } from '../Field';
6
5
  import { Select, SelectProps } from './Select';
7
6
  import { MultiSelect } from './MultiSelect';
@@ -16,7 +16,7 @@ describe('Select', () => {
16
16
  <Select idRef='1' name='name-1' label='Sort by' options={options} />
17
17
  );
18
18
  expect(container.innerHTML).toEqual(
19
- '<div id="Select--1" class="Select"><input id="1" name="name-1" type="hidden" value=""><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button></div>'
19
+ '<div id="Select--1" class="Select"><input id="1" type="hidden" name="name-1"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button></div>'
20
20
  );
21
21
  });
22
22
 
@@ -27,7 +27,7 @@ describe('Select', () => {
27
27
  const button = screen.getByRole('button', { name: /Sort by/ });
28
28
  await userEvent.click(button);
29
29
  expect(container.innerHTML).toEqual(
30
- '<div id="Select--1" class="Select"><input id="1" name="name-1" type="hidden" value=""><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button><div class="SelectOptions Select__options Select__options--down"><ul class="SelectOptions__list" tabindex="-1" role="listbox" aria-labelledby="Select__label--1" aria-activedescendant="SelectOption--foo-1"><li class="SelectOption SelectOption--active" aria-label="Foo" aria-selected="false" role="option">Foo</li><li class="SelectOption" aria-label="Bar" aria-selected="false" role="option">Bar</li><li class="SelectOption SelectOption--disabled" aria-label="Baz" aria-selected="false" role="option">Baz</li></ul></div></div>'
30
+ '<div id="Select--1" class="Select"><input id="1" type="hidden" name="name-1"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button><div class="SelectOptions Select__options Select__options--down"><ul class="SelectOptions__list" tabindex="-1" role="listbox" aria-labelledby="Select__label--1" aria-activedescendant="SelectOption--foo-1"><li class="SelectOption SelectOption--active" aria-label="Foo" aria-selected="false" role="option">Foo</li><li class="SelectOption" aria-label="Bar" aria-selected="false" role="option">Bar</li><li class="SelectOption SelectOption--disabled" aria-label="Baz" aria-selected="false" role="option">Baz</li></ul></div></div>'
31
31
  );
32
32
  });
33
33
 
@@ -45,7 +45,7 @@ describe('Select', () => {
45
45
  const button = screen.getByRole('button', { name: /Sort by/ });
46
46
  await userEvent.click(button);
47
47
  expect(container.innerHTML).toEqual(
48
- '<div id="Select--1" class="Select Select--disabled"><input id="1" name="name-1" type="hidden" value=""><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Clickable--disabled Select__value" disabled=""><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button></div>'
48
+ '<div id="Select--1" class="Select Select--disabled"><input id="1" type="hidden" name="name-1"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Clickable--disabled Select__value" disabled=""><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button></div>'
49
49
  );
50
50
  });
51
51
 
@@ -96,7 +96,7 @@ describe('Select', () => {
96
96
  const option = screen.getByLabelText('Bar');
97
97
  await userEvent.click(option);
98
98
  expect(container.innerHTML).toEqual(
99
- '<div id="Select--1" class="Select"><input id="1" name="name-1" type="hidden" value="bar"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by: </label>Bar<span class="Select__icon"></span></button></div>'
99
+ '<div id="Select--1" class="Select"><input id="1" type="hidden" name="name-1" value="bar"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by: </label>Bar<span class="Select__icon"></span></button></div>'
100
100
  );
101
101
  });
102
102
 
@@ -107,7 +107,7 @@ describe('Select', () => {
107
107
  const option = screen.getByLabelText('Bar');
108
108
  await userEvent.click(option);
109
109
  expect(container.innerHTML).toEqual(
110
- '<div id="Select--1" class="Select"><input id="1" name="name-1" type="hidden" value="bar"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value">Bar<span class="Select__icon"></span></button></div>'
110
+ '<div id="Select--1" class="Select"><input id="1" type="hidden" name="name-1" value="bar"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value">Bar<span class="Select__icon"></span></button></div>'
111
111
  );
112
112
  });
113
113
  });
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
3
 
4
- import { States } from 'storybook-states';
4
+ import { States } from '../../utilities';
5
5
  import { Stack } from '../Stack';
6
6
  import { SelectableButton, SelectableButtonProps } from './SelectableButton';
7
7
 
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { States } from 'storybook-states';
2
+ import { States } from '../../utilities';
3
3
  import * as SHAPES from '.';
4
4
 
5
5
  export default { title: 'Components/Shape' };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { States } from 'storybook-states';
3
2
  import { space } from '@moda/tokens';
3
+ import { States } from '../../utilities';
4
4
  import { Stack, StackProps } from './Stack';
5
5
 
6
6
  export default { title: 'Components/Stack' };
@@ -1,4 +1,4 @@
1
- import React, { useCallback } from 'react';
1
+ import React, { JSX, useCallback } from 'react';
2
2
  import { Clickable } from '../Clickable';
3
3
  import './Tab.scss';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react';
2
- import { States } from 'storybook-states';
2
+ import { States } from '../../utilities';
3
3
  import { Text } from '../Text';
4
4
  import { Tabs, TabsProps } from './Tabs';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
- import { States } from 'storybook-states';
3
+ import { States } from '../../utilities';
4
4
  import { Tag, TagProps } from './Tag';
5
5
 
6
6
  export default { title: 'Components/Tag' };
@@ -11,7 +11,7 @@
11
11
 
12
12
  @each $family in (sans, serif) {
13
13
  &--#{$family} {
14
- font-family: font-family($family);
14
+ font-family: om.font-family($family);
15
15
  }
16
16
  }
17
17
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { typography, colors } from '@moda/tokens';
3
- import { States } from 'storybook-states';
3
+ import { States } from '../../utilities';
4
4
  import { Text, TextProps, TextTreatment, TextColor, TextFontFamily } from './Text';
5
5
 
6
6
  export default { title: 'Components/Text' };
@@ -1,4 +1,4 @@
1
- import React, { ReactHTML } from 'react';
1
+ import React, { HTMLElementType } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { typography, colors } from '@moda/tokens';
4
4
  import './Text.scss';
@@ -8,7 +8,7 @@ export type TextColor = keyof typeof colors.all;
8
8
  export type TextFontFamily = keyof typeof typography.fonts;
9
9
 
10
10
  export type TextProps = React.HTMLAttributes<HTMLSpanElement> & {
11
- as?: keyof ReactHTML;
11
+ as?: HTMLElementType;
12
12
  treatment?: TextTreatment;
13
13
  color?: TextColor;
14
14
  family?: TextFontFamily;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { States } from 'storybook-states';
2
+ import { States } from '../../utilities';
3
3
  import { TextInput, TextInputProps } from './TextInput';
4
4
 
5
5
  export default { title: 'Components/TextInput' };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { States } from 'storybook-states';
2
+ import { States } from '../../utilities';
3
3
  import { Textarea, TextareaProps } from './Textarea';
4
4
 
5
5
  export default { title: 'Components/Textarea' };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { action } from '@storybook/addon-actions';
3
- import { States } from 'storybook-states';
3
+ import { States } from '../../utilities';
4
4
  import { Toast, ToastProps } from './Toast';
5
5
 
6
6
  export default { title: 'Components/Toast' };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { States } from 'storybook-states';
3
+ import { States } from '../../utilities';
4
4
  import { Stack } from '../Stack';
5
5
  import { VerticalDivider } from './VerticalDivider';
6
6
 
@@ -1,6 +1,9 @@
1
1
  import React, { useEffect, useCallback } from 'react';
2
2
 
3
- export const useClickOutside = (ref: React.RefObject<HTMLElement>, onClickOutside: () => void) => {
3
+ export const useClickOutside = (
4
+ ref: React.RefObject<HTMLElement | null>,
5
+ onClickOutside: () => void
6
+ ) => {
4
7
  const handleClickOutside = useCallback(
5
8
  (event: MouseEvent) => {
6
9
  if (ref.current && !ref.current.contains(event.target as Node)) onClickOutside();
package/src/index.scss CHANGED
@@ -1,4 +1,3 @@
1
1
  @forward '~@moda/tokens';
2
2
 
3
3
  @forward './mixins/mixins';
4
- @forward './functions/functions';
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import 'focus-visible';
2
+
1
3
  import { colors, typography, space, breakpoints } from '@moda/tokens';
2
4
 
3
5
  import { States } from './utilities';
@@ -1,25 +1,25 @@
1
- import React from 'react';
2
- import { isRenderProps, RenderProps } from './isRenderProps';
3
- import { StatesProps } from './StatesProps';
4
- import './State.scss';
1
+ import React, { JSX } from 'react';
2
+ import { isRenderProps, RenderProps } from '../isRenderProps';
3
+ import { StateProps } from './StateProps';
4
+ import { useStyles } from './Styles';
5
5
 
6
- interface Props {
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- props: any;
9
- children: JSX.Element | RenderProps;
6
+ interface Props<T> {
7
+ props: T;
8
+ children: JSX.Element | RenderProps<T>;
10
9
  }
11
10
 
12
- export const State: React.FC<Props> = ({ props, children, ...rest }) => {
11
+ export const State = <T extends object>({ props, children, ...rest }: Props<T>) => {
12
+ const styles = useStyles();
13
+
13
14
  const Specimen = isRenderProps(children) ? children(props) : React.cloneElement(children, props);
15
+
14
16
  const innerChildren = isRenderProps(children) ? children(props) : children;
15
17
 
16
18
  return (
17
- <div className='State' {...rest}>
19
+ <div style={styles.state} {...rest}>
18
20
  {Specimen}
19
21
 
20
- <code className='State__props'>
21
- <StatesProps props={props}>{innerChildren}</StatesProps>
22
- </code>
22
+ <StateProps props={props}>{innerChildren}</StateProps>
23
23
  </div>
24
24
  );
25
25
  };
@@ -0,0 +1,28 @@
1
+ import React, { JSX } from 'react';
2
+ import { isRenderProps } from '../isRenderProps';
3
+ import { stringifyProps } from '../stringifyProps';
4
+ import { omit } from '../omit';
5
+ import { isEmpty } from '../isEmpty';
6
+ import { useStyles } from './Styles';
7
+
8
+ interface Props {
9
+ children: JSX.Element;
10
+ props: object;
11
+ }
12
+
13
+ export const StateProps: React.FC<Props> = ({ props, children }) => {
14
+ const styles = useStyles();
15
+ const childrenProps = omit(children.props, ...Object.keys(props || {}));
16
+
17
+ return (
18
+ <div style={styles.stateProps}>
19
+ {'<'}
20
+ <span>{children.type.displayName || children.type.name}</span>{' '}
21
+ {!isEmpty(props) && <strong style={styles.statePropsActive}>{stringifyProps(props)}</strong>}{' '}
22
+ {!isRenderProps(children) && !isEmpty(childrenProps) && (
23
+ <span>{stringifyProps(childrenProps)}</span>
24
+ )}
25
+ <span>{' />'}</span>
26
+ </div>
27
+ );
28
+ };
@@ -1,22 +1,20 @@
1
- import React from 'react';
2
- import { RenderProps } from './isRenderProps';
1
+ import React, { JSX } from 'react';
2
+ import { RenderProps } from '../isRenderProps';
3
3
  import { State } from './State';
4
- import './States.scss';
5
4
 
6
- export interface Props {
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- states?: any[];
9
- children: JSX.Element | RenderProps;
5
+ export interface Props<T> {
6
+ states?: T[];
7
+ children: JSX.Element | RenderProps<T>;
10
8
  }
11
9
 
12
- export const States: React.FC<Props> = ({ states = [{}], children, ...rest }) => {
10
+ export const States = <T extends object>({ states = [{} as T], children, ...rest }: Props<T>) => {
13
11
  return (
14
- <div className='States'>
12
+ <>
15
13
  {states.map((props, index) => (
16
- <State key={index} props={props} {...rest}>
14
+ <State<T> key={index} props={props} {...rest}>
17
15
  {children}
18
16
  </State>
19
17
  ))}
20
- </div>
18
+ </>
21
19
  );
22
20
  };
@@ -0,0 +1,43 @@
1
+ import React, { ReactNode, useContext } from 'react';
2
+
3
+ export type StateStyles = {
4
+ state: React.CSSProperties;
5
+ stateProps: React.CSSProperties;
6
+ statePropsActive: React.CSSProperties;
7
+ };
8
+
9
+ export const DEFAULT_STYLES: StateStyles = {
10
+ state: {
11
+ border: '1px dotted #ddd',
12
+ padding: '0.5rem',
13
+ marginBottom: '1rem'
14
+ },
15
+ stateProps: {
16
+ display: 'block',
17
+ marginTop: '0.5rem',
18
+ paddingTop: '0.5rem',
19
+ fontFamily: "source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace",
20
+ fontSize: '0.8125rem',
21
+ color: '#999',
22
+ borderTop: '1px dotted #ddd'
23
+ },
24
+ statePropsActive: {
25
+ color: '#111',
26
+ textDecoration: 'underline'
27
+ }
28
+ };
29
+
30
+ export const Styles = React.createContext<StateStyles>(DEFAULT_STYLES);
31
+
32
+ export type StylesProvider = {
33
+ styles: Partial<StateStyles>;
34
+ children?: ReactNode;
35
+ };
36
+
37
+ export const StylesProvider: React.FC<StylesProvider> = ({ styles, children }) => {
38
+ return <Styles.Provider value={{ ...DEFAULT_STYLES, ...styles }}>{children}</Styles.Provider>;
39
+ };
40
+
41
+ export const useStyles = () => {
42
+ return useContext(Styles);
43
+ };
@@ -1 +1,2 @@
1
1
  export * from './States';
2
+ export * from './Styles';
@@ -1 +1,8 @@
1
1
  export * from './States';
2
+ export * from './isEmpty';
3
+ export * from './isRenderProps';
4
+ export * from './omit';
5
+ export * from './preventNavigation';
6
+ export * from './sample';
7
+ export * from './stringifyProps';
8
+ export * from './truncate';
@@ -0,0 +1 @@
1
+ export const isEmpty = (obj?: unknown) => Object.entries(obj || {}).length === 0;
@@ -0,0 +1,9 @@
1
+ import { JSX } from 'react';
2
+
3
+ export type RenderProps<T> = {
4
+ (props: T): JSX.Element;
5
+ };
6
+
7
+ export const isRenderProps = <T>(
8
+ children: JSX.Element | RenderProps<T>
9
+ ): children is RenderProps<T> => typeof children === 'function';
@@ -1,11 +1,6 @@
1
- const truncate = (string: string, maxLength = 25) => {
2
- if (!string) return null;
3
- const ellipsis = string.length > maxLength;
4
- return `${string.substring(0, maxLength)}${ellipsis ? '...' : ''}`;
5
- };
1
+ import { truncate } from './truncate';
6
2
 
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- export const stringifyProps = (props: any) => {
3
+ export const stringifyProps = (props: unknown) => {
9
4
  const stringifiedProps = Object.entries(props || {}).reduce((memo: string, [key, value]) => {
10
5
  if (key === 'children') return `${memo} children={...}`;
11
6
  if (typeof value === 'string') return `${memo} ${key}="${truncate(value)}"`;
@@ -0,0 +1,5 @@
1
+ export const truncate = (string: string, maxLength = 25) => {
2
+ if (!string) return null;
3
+ const ellipsis = string.length > maxLength;
4
+ return `${string.substring(0, maxLength)}${ellipsis ? '...' : ''}`;
5
+ };
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import './StatesProps.scss';
3
- interface Props {
4
- children: any;
5
- props: any;
6
- }
7
- export declare const StatesProps: React.FC<Props>;
8
- export {};
@@ -1,4 +0,0 @@
1
- export type RenderProps = {
2
- (props: any): JSX.Element;
3
- };
4
- export declare const isRenderProps: (children: JSX.Element | RenderProps) => children is RenderProps;
@@ -1 +0,0 @@
1
- export declare const stringifyProps: (props: any) => string;
File without changes
@@ -1,11 +0,0 @@
1
- @use '~@moda/om';
2
-
3
- .State {
4
- border: 1px dotted om.color(fog);
5
- padding: om.spacing(2);
6
-
7
- &__props {
8
- display: block;
9
- margin-top: om.space(2);
10
- }
11
- }
@@ -1,5 +0,0 @@
1
- @use '~@moda/om';
2
-
3
- .States {
4
- @include om.stack(6);
5
- }
@@ -1,24 +0,0 @@
1
- @use '~@moda/om';
2
-
3
- .StatesProps {
4
- @include om.text(body1, $font: code);
5
-
6
- padding-top: om.space(2);
7
- color: om.color(fog);
8
- border-top: 1px dotted om.color(elephant);
9
-
10
- > strong {
11
- text-decoration: underline;
12
- color: om.color(ink);
13
- }
14
-
15
- &::before {
16
- content: '<';
17
- color: om.color(elephant);
18
- }
19
-
20
- &::after {
21
- content: '/>';
22
- color: om.color(elephant);
23
- }
24
- }
@@ -1,31 +0,0 @@
1
- import React from 'react';
2
- import { Stack } from '../../components/Stack';
3
- import { omit } from '../omit';
4
- import { isRenderProps } from './isRenderProps';
5
- import { stringifyProps } from './stringifyProps';
6
- import './StatesProps.scss';
7
-
8
- /* eslint-disable @typescript-eslint/no-explicit-any */
9
- interface Props {
10
- children: any;
11
- props: any;
12
- }
13
- /* eslint-enable @typescript-eslint/no-explicit-any */
14
-
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- const isEmpty = (obj?: any) => Object.entries(obj || {}).length === 0;
17
-
18
- export const StatesProps: React.FC<Props> = ({ props, children }) => {
19
- const childrenProps = omit(children.props, ...Object.keys(props || {}));
20
-
21
- return (
22
- <Stack className='StatesProps' space={2} direction='horizontal'>
23
- <span>{children.type.displayName || children.type.name}</span>
24
- {!isEmpty(props) && <strong>{stringifyProps(props)}</strong>}
25
- {!isRenderProps(children) && !isEmpty(childrenProps) && (
26
- <span>{stringifyProps(childrenProps)}</span>
27
- )}
28
- <span> </span>
29
- </Stack>
30
- );
31
- };
@@ -1,7 +0,0 @@
1
- export type RenderProps = {
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
- (props: any): JSX.Element;
4
- };
5
-
6
- export const isRenderProps = (children: JSX.Element | RenderProps): children is RenderProps =>
7
- typeof children === 'function';