@peculiar/react-components 0.6.7 → 1.1.0-alpha.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 (69) hide show
  1. package/dist/cjs/Autocomplete/autocomplete.js +214 -86
  2. package/dist/cjs/Autocomplete/autocomplete.js.map +1 -1
  3. package/dist/cjs/Chip/chip.js +1 -3
  4. package/dist/cjs/Chip/chip.js.map +1 -1
  5. package/dist/cjs/NativeSelect/index.js +6 -0
  6. package/dist/cjs/NativeSelect/index.js.map +1 -0
  7. package/dist/cjs/NativeSelect/native_select.js +151 -0
  8. package/dist/cjs/NativeSelect/native_select.js.map +1 -0
  9. package/dist/cjs/Select/select.js +170 -53
  10. package/dist/cjs/Select/select.js.map +1 -1
  11. package/dist/cjs/Toast/toast.js +1 -1
  12. package/dist/cjs/Toast/toast.js.map +1 -1
  13. package/dist/cjs/hooks/index.js +3 -1
  14. package/dist/cjs/hooks/index.js.map +1 -1
  15. package/dist/cjs/hooks/use_autocomplete.js +26 -7
  16. package/dist/cjs/hooks/use_autocomplete.js.map +1 -1
  17. package/dist/cjs/hooks/use_outside_click.js +24 -0
  18. package/dist/cjs/hooks/use_outside_click.js.map +1 -0
  19. package/dist/cjs/index.js +2 -2
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/esm/Autocomplete/autocomplete.js +216 -88
  22. package/dist/esm/Autocomplete/autocomplete.js.map +1 -1
  23. package/dist/esm/Chip/chip.js +1 -3
  24. package/dist/esm/Chip/chip.js.map +1 -1
  25. package/dist/esm/NativeSelect/index.js +2 -0
  26. package/dist/esm/NativeSelect/index.js.map +1 -0
  27. package/dist/esm/NativeSelect/native_select.js +122 -0
  28. package/dist/esm/NativeSelect/native_select.js.map +1 -0
  29. package/dist/esm/Select/select.js +169 -30
  30. package/dist/esm/Select/select.js.map +1 -1
  31. package/dist/esm/Toast/toast.js +1 -1
  32. package/dist/esm/Toast/toast.js.map +1 -1
  33. package/dist/esm/hooks/index.js +1 -0
  34. package/dist/esm/hooks/index.js.map +1 -1
  35. package/dist/esm/hooks/use_autocomplete.js +26 -7
  36. package/dist/esm/hooks/use_autocomplete.js.map +1 -1
  37. package/dist/esm/hooks/use_outside_click.js +17 -0
  38. package/dist/esm/hooks/use_outside_click.js.map +1 -0
  39. package/dist/esm/index.js +2 -2
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esnext/Autocomplete/autocomplete.js +196 -87
  42. package/dist/esnext/Autocomplete/autocomplete.js.map +1 -1
  43. package/dist/esnext/Chip/chip.js +1 -2
  44. package/dist/esnext/Chip/chip.js.map +1 -1
  45. package/dist/esnext/NativeSelect/index.js +2 -0
  46. package/dist/esnext/NativeSelect/index.js.map +1 -0
  47. package/dist/esnext/NativeSelect/native_select.js +129 -0
  48. package/dist/esnext/NativeSelect/native_select.js.map +1 -0
  49. package/dist/esnext/Select/select.js +184 -44
  50. package/dist/esnext/Select/select.js.map +1 -1
  51. package/dist/esnext/Toast/toast.js +1 -1
  52. package/dist/esnext/Toast/toast.js.map +1 -1
  53. package/dist/esnext/hooks/index.js +1 -0
  54. package/dist/esnext/hooks/index.js.map +1 -1
  55. package/dist/esnext/hooks/use_autocomplete.js +26 -7
  56. package/dist/esnext/hooks/use_autocomplete.js.map +1 -1
  57. package/dist/esnext/hooks/use_outside_click.js +17 -0
  58. package/dist/esnext/hooks/use_outside_click.js.map +1 -0
  59. package/dist/esnext/index.js +2 -2
  60. package/dist/esnext/index.js.map +1 -1
  61. package/dist/types/Autocomplete/autocomplete.d.ts +4 -11
  62. package/dist/types/NativeSelect/index.d.ts +1 -0
  63. package/dist/types/NativeSelect/native_select.d.ts +76 -0
  64. package/dist/types/Select/select.d.ts +65 -33
  65. package/dist/types/hooks/index.d.ts +1 -0
  66. package/dist/types/hooks/use_autocomplete.d.ts +4 -1
  67. package/dist/types/hooks/use_outside_click.d.ts +2 -0
  68. package/dist/types/index.d.ts +2 -2
  69. package/package.json +5 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_outside_click.js","sourceRoot":"","sources":["../../../src/hooks/use_outside_click.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAkB,EAAE,EAAE;IACpD,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAE/B,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,WAAW,GAAG,CAAC,KAAiB,EAAE,EAAE;YACxC,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;gBACtD,QAAQ,EAAE,CAAC;aACZ;QACH,CAAC,CAAC;QAEF,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QAEtD,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEpB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
@@ -20,9 +20,9 @@ export * from './Popper';
20
20
  export * from './Popover';
21
21
  export * from './Portal';
22
22
  export * from './Radio';
23
- export * from './Select';
23
+ export * from './NativeSelect';
24
24
  export * from './Skeleton';
25
- export * from './Autocomplete';
25
+ export * from './Select';
26
26
  export * from './Slide';
27
27
  export * from './Slider';
28
28
  export * from './Switch';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;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AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,QAAQ,CAAC"}
@@ -43,10 +43,6 @@ export declare type AutocompleteOwnProps<T, Multiple extends boolean | undefined
43
43
  * The maximum number of tags that will be visible when not focused.
44
44
  */
45
45
  limitTags?: number;
46
- /**
47
- * If `true`, the popup search input will be hidden.
48
- */
49
- disableSearch?: boolean;
50
46
  /**
51
47
  * If `true`, the autocomplete will be disabled.
52
48
  */
@@ -59,10 +55,6 @@ export declare type AutocompleteOwnProps<T, Multiple extends boolean | undefined
59
55
  * If `true`, the `input` element is required.
60
56
  */
61
57
  required?: boolean;
62
- /**
63
- * Text to display when in the create button element.
64
- */
65
- createOptionText?: string;
66
58
  /**
67
59
  * If `true`, the create button element will be shown.
68
60
  */
@@ -80,6 +72,10 @@ export declare type AutocompleteOwnProps<T, Multiple extends boolean | undefined
80
72
  * Render the option, use `getOptionLabel` by default.
81
73
  */
82
74
  renderOption?: (props: object, option: T) => React.ReactNode;
75
+ /**
76
+ * Render the tags elements.
77
+ */
78
+ renderTag?: (props: object, option: T) => React.ReactNode;
83
79
  /**
84
80
  * The label to display when the tags are truncated (`limitTags`).
85
81
  */
@@ -95,14 +91,11 @@ export declare type AutocompleteOwnProps<T, Multiple extends boolean | undefined
95
91
  export declare const Autocomplete: {
96
92
  <T, Multiple extends boolean = false>(props: AutocompleteOwnProps<T, Multiple>): JSX.Element;
97
93
  defaultProps: {
98
- disableSearch: boolean;
99
94
  noOptionsText: string;
100
95
  loading: boolean;
101
96
  loadingText: string;
102
- limitTags: number;
103
97
  required: boolean;
104
98
  allowCreateOption: boolean;
105
- createOptionText: string;
106
99
  size: string;
107
100
  };
108
101
  };
@@ -0,0 +1 @@
1
+ export { NativeSelect } from './native_select';
@@ -0,0 +1,76 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Types.
4
+ */
5
+ declare type NativeSelectOwnProps = {
6
+ options: {
7
+ value: string;
8
+ label: string;
9
+ }[];
10
+ /**
11
+ * If `true`, the component is disabled.
12
+ */
13
+ disabled?: boolean;
14
+ /**
15
+ * The size of the select.
16
+ */
17
+ size?: ('small' | 'medium' | 'large');
18
+ /**
19
+ * The className of the component.
20
+ */
21
+ className?: string;
22
+ /**
23
+ * Attributes applied to the `input` element.
24
+ */
25
+ inputProps?: React.SelectHTMLAttributes<HTMLSelectElement>;
26
+ /**
27
+ * The default value. Use when the component is not controlled.
28
+ */
29
+ defaultValue?: string;
30
+ /**
31
+ * The id of the `input` element.
32
+ */
33
+ id?: string;
34
+ /**
35
+ * The label of the input. It is only used for layout.
36
+ */
37
+ label?: string;
38
+ /**
39
+ * The value of the `input` element, required for a controlled component.
40
+ */
41
+ value?: string;
42
+ /**
43
+ * The short hint displayed in the `input` before the user enters a value.
44
+ */
45
+ placeholder?: string;
46
+ /**
47
+ * If `true`, the `input` element is required.
48
+ */
49
+ required?: boolean;
50
+ /**
51
+ * Name attribute of the `input` element.
52
+ */
53
+ name?: string;
54
+ /**
55
+ * Pass a ref to the `input` element.
56
+ */
57
+ inputRef?: React.ForwardedRef<HTMLSelectElement>;
58
+ /**
59
+ * If `true`, the `input` element is focused during the first mount.
60
+ */
61
+ autoFocus?: boolean;
62
+ /**
63
+ * If `true`, the `input` will indicate an error.
64
+ */
65
+ error?: boolean;
66
+ errorText?: string;
67
+ /**
68
+ * Callback fired when the value is changed.
69
+ */
70
+ onChange?: React.ChangeEventHandler<HTMLSelectElement>;
71
+ };
72
+ /**
73
+ *
74
+ */
75
+ export declare const NativeSelect: React.ForwardRefExoticComponent<NativeSelectOwnProps & Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> & React.RefAttributes<HTMLDivElement>>;
76
+ export {};
@@ -1,76 +1,108 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
+ import { UseAutocompleteProps, UseAutocompleteReturnType, AutocompleteValue } from '../hooks';
2
3
  /**
3
4
  * Types.
4
5
  */
5
- declare type SelectOwnProps = {
6
- options: {
7
- value: string;
8
- label: string;
9
- }[];
6
+ export declare type SelectRenderGroupParams = {
7
+ key: string | number;
8
+ group: string;
9
+ children?: React.ReactNode;
10
+ };
11
+ export declare type SelectOwnProps<T, Multiple extends boolean | undefined = undefined> = UseAutocompleteProps<T, Multiple> & {
10
12
  /**
11
- * If `true`, the component is disabled.
13
+ * The className of the component.
12
14
  */
13
- disabled?: boolean;
15
+ className?: string;
14
16
  /**
15
- * The size of the select.
17
+ * The size of the root component.
16
18
  */
17
19
  size?: ('small' | 'medium' | 'large');
18
20
  /**
19
- * The className of the component.
21
+ * The short hint displayed in the `input` before the user enters a value.
20
22
  */
21
- className?: string;
23
+ placeholder?: string;
22
24
  /**
23
- * Attributes applied to the `input` element.
25
+ * The label content.
24
26
  */
25
- inputProps?: React.SelectHTMLAttributes<HTMLSelectElement>;
27
+ label?: string;
26
28
  /**
27
- * The default value. Use when the component is not controlled.
29
+ * Text to display when there are no options.
28
30
  */
29
- defaultValue?: string;
31
+ noOptionsText?: React.ReactNode;
30
32
  /**
31
- * The id of the `input` element.
33
+ * If `true`, the component is in a loading state.
34
+ * This shows the `loadingText` in place of suggestions (only if there are no
35
+ * suggestions to show, e.g. `options` are empty).
32
36
  */
33
- id?: string;
37
+ loading?: boolean;
34
38
  /**
35
- * The label of the input. It is only used for layout.
39
+ * Text to display when in a loading state.
36
40
  */
37
- label?: string;
41
+ loadingText?: React.ReactNode;
38
42
  /**
39
- * The value of the `input` element, required for a controlled component.
43
+ * The maximum number of tags that will be visible when not focused.
40
44
  */
41
- value?: string;
45
+ limitTags?: number;
42
46
  /**
43
- * The short hint displayed in the `input` before the user enters a value.
47
+ * If `true`, the popup search input will be hidden.
44
48
  */
45
- placeholder?: string;
49
+ disableSearch?: boolean;
46
50
  /**
47
- * If `true`, the `input` element is required.
51
+ * If `true`, the autocomplete will be disabled.
48
52
  */
49
- required?: boolean;
53
+ disabled?: boolean;
50
54
  /**
51
55
  * Name attribute of the `input` element.
52
56
  */
53
57
  name?: string;
54
58
  /**
55
- * Pass a ref to the `input` element.
59
+ * If `true`, the `input` element is required.
56
60
  */
57
- inputRef?: React.ForwardedRef<HTMLSelectElement>;
61
+ required?: boolean;
58
62
  /**
59
- * If `true`, the `input` element is focused during the first mount.
63
+ * Text to display when in the create button element.
60
64
  */
61
- autoFocus?: boolean;
65
+ createOptionText?: string;
66
+ /**
67
+ * If `true`, the create button element will be shown.
68
+ */
69
+ allowCreateOption?: boolean;
62
70
  /**
63
71
  * If `true`, the `input` will indicate an error.
64
72
  */
65
73
  error?: boolean;
66
74
  errorText?: string;
67
75
  /**
68
- * Callback fired when the value is changed.
76
+ * Render the root element.
69
77
  */
70
- onChange?: React.ChangeEventHandler<HTMLSelectElement>;
78
+ renderRoot?: (props: object, value: AutocompleteValue<T, Multiple>, getTagProps: UseAutocompleteReturnType<T, Multiple>['getTagProps']) => React.ReactNode;
79
+ /**
80
+ * Render the option, use `getOptionLabel` by default.
81
+ */
82
+ renderOption?: (props: object, option: T) => React.ReactNode;
83
+ /**
84
+ * The label to display when the tags are truncated (`limitTags`).
85
+ */
86
+ getLimitTagsText?: (more: number) => string;
87
+ /**
88
+ * Callback fired when the create button clicked.
89
+ */
90
+ onCreate?: (event: React.SyntheticEvent, value: string) => void;
71
91
  };
72
92
  /**
73
93
  *
74
94
  */
75
- export declare const Select: React.ForwardRefExoticComponent<SelectOwnProps & Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> & React.RefAttributes<HTMLDivElement>>;
76
- export {};
95
+ export declare const Select: {
96
+ <T, Multiple extends boolean = false>(props: SelectOwnProps<T, Multiple>): JSX.Element;
97
+ defaultProps: {
98
+ disableSearch: boolean;
99
+ noOptionsText: string;
100
+ loading: boolean;
101
+ loadingText: string;
102
+ limitTags: number;
103
+ required: boolean;
104
+ allowCreateOption: boolean;
105
+ createOptionText: string;
106
+ size: string;
107
+ };
108
+ };
@@ -12,3 +12,4 @@ export type { UseAutocompleteProps, UseAutocompleteReturnType, AutocompleteValue
12
12
  export { useEventCallback } from './use_event_callback';
13
13
  export { useEnhancedEffect } from './use_enhanced_effect';
14
14
  export { useDebounceCallback } from './use_debounce_callback';
15
+ export { useOutsideClick } from './use_outside_click';
@@ -98,7 +98,10 @@ export declare type UseAutocompleteReturnType<T, Multiple extends boolean | unde
98
98
  getInputLabelProps: () => React.HTMLAttributes<HTMLLabelElement>;
99
99
  getRootProps: () => React.HTMLAttributes<HTMLDivElement>;
100
100
  getInputProps: () => React.HTMLAttributes<HTMLInputElement>;
101
- getClearProps: () => React.HTMLAttributes<HTMLDivElement>;
101
+ getClearProps: () => {
102
+ tabIndex: -1;
103
+ onClick: (event: React.SyntheticEvent) => void;
104
+ };
102
105
  getPopoverProps: () => Pick<Required<PopoverProps>, 'open' | 'anchorEl' | 'onClose' | 'onKeyDown'>;
103
106
  getTagProps: (option: T, index: number) => {
104
107
  key: number;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const useOutsideClick: (callback: Function) => React.MutableRefObject<any>;
@@ -20,9 +20,9 @@ export * from './Popper';
20
20
  export * from './Popover';
21
21
  export * from './Portal';
22
22
  export * from './Radio';
23
- export * from './Select';
23
+ export * from './NativeSelect';
24
24
  export * from './Skeleton';
25
- export * from './Autocomplete';
25
+ export * from './Select';
26
26
  export * from './Slide';
27
27
  export * from './Slider';
28
28
  export * from './Switch';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peculiar/react-components",
3
3
  "private": false,
4
- "version": "0.6.7",
4
+ "version": "1.1.0-alpha.0",
5
5
  "author": "PeculiarVentures Team",
6
6
  "description": "A simple and customizable component library to build faster, beautiful, and more accessible React applications.",
7
7
  "keywords": [
@@ -48,7 +48,7 @@
48
48
  "dependencies": {
49
49
  "@emotion/react": "^11.11.1",
50
50
  "@emotion/styled": "^11.11.0",
51
- "@peculiar/color": "^0.1.3",
51
+ "@peculiar/color": "^0.1.4",
52
52
  "@popperjs/core": "^2.11.7",
53
53
  "@types/flat": "^5.0.2",
54
54
  "@types/react-transition-group": "^4.4.5",
@@ -72,14 +72,14 @@
72
72
  "storybook": "7.6.7",
73
73
  "storybook-dark-mode": "^3.0.3",
74
74
  "typescript": "^4.6.3",
75
- "vite": "^5.0.8"
75
+ "vite": "^5.4.8"
76
76
  },
77
77
  "publishConfig": {
78
78
  "access": "public"
79
79
  },
80
80
  "engines": {
81
- "node": ">=12.x"
81
+ "node": ">=18.x"
82
82
  },
83
83
  "license": "MIT",
84
- "gitHead": "3b5136cc8aec8d4a2bcb9b2a5928ffef5f5f4843"
84
+ "gitHead": "0784e5b060ee118e92243b34520dd30a6e384279"
85
85
  }