uikit-react-public 0.11.13 → 0.11.15

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 (40) hide show
  1. package/dist/components/Button/Button.d.ts +21 -3
  2. package/dist/components/Button/Button.stories.d.ts +1 -1
  3. package/dist/components/Button/buttonPrimaryStyle.d.ts +2 -2
  4. package/dist/components/Button/buttonSecondaryStyle.d.ts +2 -2
  5. package/dist/components/Button/buttonTertiaryStyle.d.ts +2 -2
  6. package/dist/components/Button/index.d.ts +1 -1
  7. package/dist/components/Select/Select.d.ts +3 -8
  8. package/dist/components/Select/Select.stories.d.ts +50 -2
  9. package/dist/components/Select/Select.types.d.ts +122 -0
  10. package/dist/components/Select/index.d.ts +1 -1
  11. package/dist/components/Select/subcomponents/CustomOption.d.ts +3 -0
  12. package/dist/components/Select/subcomponents/CustomSelect.d.ts +3 -0
  13. package/dist/components/Select/subcomponents/NativeSelect.d.ts +3 -0
  14. package/dist/components/Select/subcomponents/Panel.d.ts +3 -0
  15. package/dist/components/Select/subcomponents/VisibleField.d.ts +9 -0
  16. package/dist/components/Select/subcomponents/index.d.ts +5 -0
  17. package/dist/index.js +2875 -2549
  18. package/lib/Welcome.mdx +7 -7
  19. package/lib/components/Button/Button.tsx +36 -7
  20. package/lib/components/Button/buttonPrimaryStyle.ts +4 -4
  21. package/lib/components/Button/buttonSecondaryStyle.ts +4 -4
  22. package/lib/components/Button/buttonTertiaryStyle.ts +3 -3
  23. package/lib/components/Button/index.ts +1 -1
  24. package/lib/components/Icon/svgs/AvatarSvg.tsx +2 -2
  25. package/lib/components/Icon/svgs/ChevronDownSvg.tsx +2 -5
  26. package/lib/components/Select/Select.stories.tsx +192 -13
  27. package/lib/components/Select/Select.tsx +33 -76
  28. package/lib/components/Select/Select.types.ts +146 -0
  29. package/lib/components/Select/__tests__/Select.test.tsx +99 -20
  30. package/lib/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +33 -37
  31. package/lib/components/Select/index.ts +1 -1
  32. package/lib/components/Select/subcomponents/CustomOption.tsx +74 -0
  33. package/lib/components/Select/subcomponents/CustomSelect.tsx +211 -0
  34. package/lib/components/Select/subcomponents/NativeSelect.tsx +109 -0
  35. package/lib/components/Select/subcomponents/Panel.tsx +46 -0
  36. package/lib/components/Select/subcomponents/VisibleField.tsx +69 -0
  37. package/lib/components/Select/subcomponents/index.tsx +5 -0
  38. package/package.json +1 -1
  39. package/dist/components/Button/Button.types.d.ts +0 -26
  40. package/lib/components/Button/Button.types.ts +0 -46
@@ -1,4 +1,22 @@
1
- import { ButtonProps } from './Button.types';
1
+ import { ReactElement, ElementType, ComponentPropsWithRef } from 'react';
2
2
  export declare const NAME = "ucl-uikit-button";
3
- declare const _default: import('react').MemoExoticComponent<({ as, variant, destructive, size, disabled, icon, iconPosition, tooltip, loading, fullWidth, testId, ref, children, className, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element>;
4
- export default _default;
3
+ type PolymorphicRef<C extends ElementType> = ComponentPropsWithRef<C>['ref'];
4
+ export interface ButtonBaseProps {
5
+ variant?: 'primary' | 'secondary' | 'tertiary';
6
+ destructive?: boolean;
7
+ size?: 'large' | 'default' | 'small';
8
+ disabled?: boolean;
9
+ icon?: ReactElement;
10
+ iconPosition?: 'left' | 'right';
11
+ tooltip?: string;
12
+ loading?: boolean;
13
+ fullWidth?: boolean;
14
+ testId?: string;
15
+ }
16
+ export type ButtonProps<C extends ElementType = 'button'> = {
17
+ as?: C;
18
+ ref?: PolymorphicRef<C>;
19
+ } & ButtonBaseProps & Omit<ComponentPropsWithRef<C>, keyof ButtonBaseProps | 'as'>;
20
+ declare const Button: <C extends ElementType = "button">({ as, variant, destructive, size, disabled, icon, iconPosition, tooltip, loading, fullWidth, testId, ref, children, className, ...props }: ButtonProps<C>) => import("react/jsx-runtime").JSX.Element;
21
+ declare const MemoizedButton: typeof Button;
22
+ export default MemoizedButton;
@@ -1,7 +1,7 @@
1
1
  import { StoryObj } from '@storybook/react';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: import('react').MemoExoticComponent<({ as, variant, destructive, size, disabled, icon, iconPosition, tooltip, loading, fullWidth, testId, ref, children, className, ...props }: import('./Button.types').ButtonProps) => import("react/jsx-runtime").JSX.Element>;
4
+ component: <C extends import('react').ElementType = "button">({ as, variant, destructive, size, disabled, icon, iconPosition, tooltip, loading, fullWidth, testId, ref, children, className, ...props }: import('./Button').ButtonProps<C>) => import("react/jsx-runtime").JSX.Element;
5
5
  parameters: {
6
6
  layout: string;
7
7
  };
@@ -1,4 +1,4 @@
1
1
  import { ThemeType } from '../../theme';
2
- import { ButtonProps } from './Button.types';
3
- declare const buttonPrimaryStyle: (theme: ThemeType, destructive: ButtonProps["destructive"], disabled: ButtonProps["disabled"], loading: ButtonProps["loading"]) => string;
2
+ import { ButtonBaseProps } from './Button';
3
+ declare const buttonPrimaryStyle: (theme: ThemeType, destructive: ButtonBaseProps["destructive"], disabled: ButtonBaseProps["disabled"], loading: ButtonBaseProps["loading"]) => string;
4
4
  export default buttonPrimaryStyle;
@@ -1,4 +1,4 @@
1
1
  import { ThemeType } from '../../theme';
2
- import { ButtonProps } from './Button.types';
3
- declare const buttonSecondaryStyle: (theme: ThemeType, destructive: ButtonProps["destructive"], disabled: ButtonProps["disabled"], loading: ButtonProps["loading"]) => string;
2
+ import { ButtonBaseProps } from './Button';
3
+ declare const buttonSecondaryStyle: (theme: ThemeType, destructive: ButtonBaseProps["destructive"], disabled: ButtonBaseProps["disabled"], loading: ButtonBaseProps["loading"]) => string;
4
4
  export default buttonSecondaryStyle;
@@ -1,4 +1,4 @@
1
1
  import { ThemeType } from '../../theme';
2
- import { ButtonProps } from './Button.types';
3
- declare const buttonTertiaryStyle: (theme: ThemeType, disabled: ButtonProps["disabled"], loading: ButtonProps["loading"]) => string;
2
+ import { ButtonBaseProps } from './Button';
3
+ declare const buttonTertiaryStyle: (theme: ThemeType, disabled: ButtonBaseProps["disabled"], loading: ButtonBaseProps["loading"]) => string;
4
4
  export default buttonTertiaryStyle;
@@ -1,2 +1,2 @@
1
1
  export { default } from './Button';
2
- export type { ButtonProps } from './Button.types';
2
+ export type { ButtonProps, ButtonBaseProps } from './Button';
@@ -1,8 +1,3 @@
1
- import { SelectHTMLAttributes } from 'react';
2
- export declare const NAME = "ucl-uikit-select";
3
- export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
4
- testId?: string;
5
- }
6
- export type Ref = HTMLSelectElement;
7
- declare const _default: import('react').NamedExoticComponent<SelectProps & import('react').RefAttributes<HTMLSelectElement>>;
8
- export default _default;
1
+ import { SelectProps } from './Select.types';
2
+ declare const Select: (props: SelectProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default Select;
@@ -1,9 +1,57 @@
1
1
  import { StoryObj } from '@storybook/react';
2
2
  declare const meta: {
3
3
  title: string;
4
- component: import('react').NamedExoticComponent<import('./Select').SelectProps & import('react').RefAttributes<HTMLSelectElement>>;
4
+ component: (props: import('./Select.types').SelectProps) => import("react/jsx-runtime").JSX.Element;
5
+ argTypes: {
6
+ value: {
7
+ control: {
8
+ type: "text";
9
+ };
10
+ };
11
+ native: {
12
+ control: {
13
+ type: "boolean";
14
+ };
15
+ };
16
+ disabled: {
17
+ control: {
18
+ type: "boolean";
19
+ };
20
+ };
21
+ placeholder: {
22
+ control: {
23
+ type: "text";
24
+ };
25
+ };
26
+ testId: {
27
+ control: {
28
+ type: "text";
29
+ };
30
+ };
31
+ width: {
32
+ control: {
33
+ type: "range";
34
+ min: number;
35
+ max: number;
36
+ step: number;
37
+ };
38
+ };
39
+ };
40
+ args: {
41
+ value: undefined;
42
+ onChange: () => void;
43
+ options: {
44
+ text: string;
45
+ value: string;
46
+ }[];
47
+ };
5
48
  };
6
49
  export default meta;
7
50
  type Story = StoryObj<typeof meta>;
8
51
  export declare const Default: Story;
9
- export declare const NoOptions: Story;
52
+ export declare const Native: Story;
53
+ export declare const OptionsWithIcons: Story;
54
+ export declare const Disabled: Story;
55
+ export declare const WithPlaceholder: Story;
56
+ export declare const SingleLongOption: Story;
57
+ export declare const ManyOptions: Story;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Represents an 'option' in the <Select>
3
+ * Maps to a native <option> element in <NativeSelect>
4
+ * or a <CustomOption> in <CustomSelect>
5
+ */
6
+ export type OptionData = {
7
+ /**
8
+ * Display text shown to the user
9
+ */
10
+ text: string;
11
+ /**
12
+ * Data-friendly value that is returned when the option is selected
13
+ * We assume this will be submitted to a server or used in some other way
14
+ */
15
+ value: string;
16
+ /**
17
+ * Optional icon to be displayed to the left of the option text.
18
+ * Only used by <CustomOption>
19
+ * Takes in an actual <Icon> component
20
+ */
21
+ icon?: React.ReactNode;
22
+ };
23
+ /**
24
+ * Utility type we expose to developers
25
+ * We expect this to be used in typing event handlers
26
+ * This only applies to the top-level <Select> component
27
+ */
28
+ export type SelectEvent = React.ChangeEvent<HTMLSelectElement> | React.MouseEvent | React.KeyboardEvent;
29
+ /**
30
+ * Top level props that <Select> accepts when implemented
31
+ */
32
+ interface BaseSelectProps {
33
+ /**
34
+ * An array of option data, to be rendered either natively or custom
35
+ */
36
+ options: OptionData[];
37
+ /**
38
+ * The currently selected value
39
+ * This determines which option is shown when the select is closed
40
+ */
41
+ value: string | undefined | null;
42
+ /**
43
+ * Generic onChange that splits into native and custom versions
44
+ * The original event is exposed, and the value always returns the value of the selected option
45
+ */
46
+ onChange: (event: SelectEvent, value: string) => void;
47
+ /**
48
+ * Prevents use, including focus events
49
+ */
50
+ disabled?: boolean | undefined;
51
+ /**
52
+ * Placeholder text shown when no option is selected
53
+ * Displayed in visible field of custom implementation
54
+ * or as a disabled option in the native implementation
55
+ */
56
+ placeholder?: string;
57
+ /**
58
+ * Specify a specific width if the default (325px) is not suitable
59
+ */
60
+ width?: number;
61
+ /**
62
+ * Test ID for testing purposes
63
+ * This is passed to the root element of the component
64
+ * as `data-testid`
65
+ */
66
+ testId?: string;
67
+ /**
68
+ * Optional className for styling
69
+ * This is passed to the root element of the component
70
+ * for additional CSS styling via Emotion.
71
+ */
72
+ className?: string;
73
+ /**
74
+ * Native flag determines which implementation to use
75
+ */
76
+ native?: boolean;
77
+ }
78
+ export type SelectProps = BaseSelectProps & (({
79
+ native: true;
80
+ ref?: React.RefObject<HTMLSelectElement | null>;
81
+ } & Omit<React.SelectHTMLAttributes<HTMLSelectElement>, keyof BaseSelectProps>) | ({
82
+ native?: false;
83
+ ref?: React.RefObject<HTMLDivElement | null>;
84
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, keyof BaseSelectProps>));
85
+ /**
86
+ * Internal props for the custom implementation, with <div> as root element
87
+ * onChange already exists on <div>. We override it.
88
+ */
89
+ export interface CustomSelectProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
90
+ options: OptionData[];
91
+ value: string | undefined | null;
92
+ onChange: (event: React.MouseEvent | React.KeyboardEvent, value: string) => void;
93
+ disabled?: boolean;
94
+ placeholder?: string;
95
+ width?: number;
96
+ testId?: string;
97
+ className?: string;
98
+ ref?: React.RefObject<HTMLDivElement | null>;
99
+ }
100
+ /**
101
+ * Internal props for native implementation, with <select> as root element
102
+ * Default props like value and onChange are passed to the <select> element automatically
103
+ */
104
+ export interface NativeSelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
105
+ options: OptionData[];
106
+ placeholder?: string;
107
+ width?: number;
108
+ testId?: string;
109
+ className?: string;
110
+ ref?: React.RefObject<HTMLSelectElement | null>;
111
+ }
112
+ /**
113
+ * Each option as displayed in the Panel of <CustomSelect>
114
+ * Roughly equivalent to a custom version of <option>
115
+ */
116
+ export interface CustomOptionProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect'> {
117
+ value: string;
118
+ testId?: string;
119
+ isSelected?: boolean;
120
+ onSelect: (event: React.MouseEvent, value: string) => void;
121
+ }
122
+ export {};
@@ -1,2 +1,2 @@
1
1
  export { default } from './Select';
2
- export type { SelectProps } from './Select';
2
+ export type { SelectProps, OptionData, SelectEvent } from './Select.types';
@@ -0,0 +1,3 @@
1
+ import { CustomOptionProps } from '../Select.types';
2
+ declare const CustomOption: ({ value, isSelected, onSelect, testId, className, children, ...props }: CustomOptionProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default CustomOption;
@@ -0,0 +1,3 @@
1
+ import { CustomSelectProps } from '../Select.types';
2
+ declare const CustomSelect: ({ value, options, onChange, disabled, placeholder, width, testId, className, ref, ...props }: CustomSelectProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default CustomSelect;
@@ -0,0 +1,3 @@
1
+ import { NativeSelectProps } from '../Select.types';
2
+ declare const NativeSelect: ({ options, width, disabled, placeholder, testId, className, ...props }: NativeSelectProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default NativeSelect;
@@ -0,0 +1,3 @@
1
+ type PanelProps = React.ComponentPropsWithoutRef<'div'>;
2
+ declare const Panel: (props: PanelProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default Panel;
@@ -0,0 +1,9 @@
1
+ import { OptionData } from '../Select.types';
2
+ interface VisibleFieldProps {
3
+ isOpen?: boolean;
4
+ disabled?: boolean;
5
+ selectedOption: OptionData | null | undefined;
6
+ placeholder?: string;
7
+ }
8
+ declare const Field: ({ selectedOption, isOpen, placeholder, disabled, }: VisibleFieldProps) => import("react/jsx-runtime").JSX.Element;
9
+ export default Field;
@@ -0,0 +1,5 @@
1
+ export { default as CustomSelect } from './CustomSelect';
2
+ export { default as NativeSelect } from './NativeSelect';
3
+ export { default as CustomOption } from './CustomOption';
4
+ export { default as Panel } from './Panel';
5
+ export { default as VisibleField } from './VisibleField';