@companix/uikit 0.0.2 → 0.0.4

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 (222) hide show
  1. package/dist/Button/index.d.ts +20 -0
  2. package/dist/ButtonGroup/index.d.ts +7 -0
  3. package/dist/Checkbox/index.d.ts +10 -0
  4. package/dist/Countdown/index.d.ts +7 -0
  5. package/dist/DateInput/index.d.ts +13 -0
  6. package/dist/DatePicker/Calendar.d.ts +14 -0
  7. package/dist/DatePicker/CalendarHeader.d.ts +10 -0
  8. package/dist/DatePicker/index.d.ts +12 -0
  9. package/dist/Dialog/index.d.ts +12 -0
  10. package/dist/DialogAlert/Alert.d.ts +19 -0
  11. package/dist/DialogAlert/Viewport.d.ts +8 -0
  12. package/dist/DialogAlert/index.d.ts +11 -0
  13. package/dist/Drawer/index.d.ts +13 -0
  14. package/dist/File/index.d.ts +10 -0
  15. package/dist/Form/index.d.ts +17 -0
  16. package/dist/Icon/index.d.ts +7 -0
  17. package/dist/LoadButton/index.d.ts +5 -0
  18. package/dist/NumberInput/index.d.ts +6 -0
  19. package/dist/OptionItem/OptionItem.d.ts +7 -0
  20. package/dist/OptionItem/OptionsList.d.ts +8 -0
  21. package/dist/Popover/index.d.ts +26 -0
  22. package/dist/Radio/index.d.ts +20 -0
  23. package/dist/Scrollable/ImitateScroll.d.ts +10 -0
  24. package/dist/Scrollable/index.d.ts +33 -0
  25. package/dist/Select/SelectInput.d.ts +14 -0
  26. package/dist/Select/index.d.ts +15 -0
  27. package/dist/SelectTags/index.d.ts +15 -0
  28. package/dist/Spinner/index.d.ts +8 -0
  29. package/dist/Stepper/index.d.ts +8 -0
  30. package/dist/Switch/index.d.ts +10 -0
  31. package/dist/Tabs/index.d.ts +13 -0
  32. package/dist/TextArea/index.d.ts +7 -0
  33. package/dist/Toaster/RemoveListener.d.ts +3 -0
  34. package/dist/Toaster/Toast.d.ts +9 -0
  35. package/dist/Toaster/Viewport.d.ts +13 -0
  36. package/dist/Toaster/index.d.ts +15 -0
  37. package/dist/Tooltip/index.d.ts +8 -0
  38. package/dist/__hooks/use-frooze-closing.d.ts +5 -0
  39. package/dist/__hooks/use-loading.d.ts +8 -0
  40. package/dist/__hooks/use-local-storage.d.ts +1 -0
  41. package/dist/__hooks/use-popover-position.d.ts +8 -0
  42. package/dist/__hooks/use-previos.d.ts +2 -0
  43. package/dist/__hooks/use-resize.d.ts +3 -0
  44. package/dist/__hooks/use-scrollbox.d.ts +7 -0
  45. package/dist/__hooks/use-stepper-input.d.ts +13 -0
  46. package/dist/__hooks/use-update.d.ts +1 -0
  47. package/dist/__hooks/useCalendar.d.ts +17 -0
  48. package/dist/__hooks/useCalendarOptions-copy.d.ts +22 -0
  49. package/dist/__hooks/useCalendarOptions.d.ts +31 -0
  50. package/dist/__libs/calendar.d.ts +25 -0
  51. package/dist/__utils/utils.d.ts +25 -0
  52. package/dist/bundle.es.js +58 -0
  53. package/dist/bundle.es10.js +38 -0
  54. package/dist/bundle.es11.js +33 -0
  55. package/dist/bundle.es12.js +18 -0
  56. package/dist/bundle.es13.js +10 -0
  57. package/dist/bundle.es14.js +35 -0
  58. package/dist/bundle.es15.js +27 -0
  59. package/dist/bundle.es16.js +23 -0
  60. package/dist/bundle.es17.js +24 -0
  61. package/dist/bundle.es18.js +15 -0
  62. package/dist/bundle.es19.js +40 -0
  63. package/dist/bundle.es2.js +45 -0
  64. package/dist/bundle.es20.js +18 -0
  65. package/dist/bundle.es21.js +36 -0
  66. package/dist/bundle.es22.js +23 -0
  67. package/dist/bundle.es23.js +42 -0
  68. package/dist/bundle.es24.js +113 -0
  69. package/dist/bundle.es25.js +114 -0
  70. package/dist/bundle.es26.js +38 -0
  71. package/dist/bundle.es27.js +13 -0
  72. package/dist/bundle.es28.js +27 -0
  73. package/dist/bundle.es29.js +38 -0
  74. package/dist/bundle.es3.js +13 -0
  75. package/dist/bundle.es30.js +26 -0
  76. package/dist/bundle.es31.js +83 -0
  77. package/dist/bundle.es32.js +20 -0
  78. package/dist/bundle.es33.js +16 -0
  79. package/dist/bundle.es34.js +24 -0
  80. package/dist/bundle.es35.js +7 -0
  81. package/dist/bundle.es36.js +23 -0
  82. package/dist/bundle.es37.js +16 -0
  83. package/dist/bundle.es38.js +72 -0
  84. package/dist/bundle.es39.js +70 -0
  85. package/dist/bundle.es4.js +87 -0
  86. package/dist/bundle.es40.js +34 -0
  87. package/dist/bundle.es41.js +70 -0
  88. package/dist/bundle.es42.js +33 -0
  89. package/dist/bundle.es43.js +77 -0
  90. package/dist/bundle.es44.js +51 -0
  91. package/dist/bundle.es45.js +45 -0
  92. package/dist/bundle.es5.js +87 -0
  93. package/dist/bundle.es6.js +80 -0
  94. package/dist/bundle.es7.js +28 -0
  95. package/dist/bundle.es8.js +87 -0
  96. package/dist/bundle.es9.js +75 -0
  97. package/dist/index.d.ts +30 -0
  98. package/{src → dist}/index.scss +3 -0
  99. package/{src → dist}/mixins.scss +4 -3
  100. package/{src → dist}/theme.scss +0 -2
  101. package/dist/types.d.ts +13 -0
  102. package/package.json +10 -6
  103. package/.eslintrc +0 -54
  104. package/declaration.d.ts +0 -4
  105. package/index.html +0 -12
  106. package/playground/App.tsx +0 -166
  107. package/playground/Example.tsx +0 -14
  108. package/playground/Test.tsx +0 -44
  109. package/playground/animation-test-1/index.scss +0 -20
  110. package/playground/animation-test-1/index.tsx +0 -17
  111. package/playground/animation-test-2/index.scss +0 -62
  112. package/playground/animation-test-2/index.tsx +0 -32
  113. package/playground/bootstrap.tsx +0 -19
  114. package/playground/buttons/index.tsx +0 -132
  115. package/playground/checkbox/index.tsx +0 -64
  116. package/playground/date-input/index.tsx +0 -45
  117. package/playground/date-picker/index.tsx +0 -41
  118. package/playground/dialog/index.tsx +0 -92
  119. package/playground/dialog-alert/index.tsx +0 -47
  120. package/playground/drawer/index.tsx +0 -55
  121. package/playground/index.css +0 -33
  122. package/playground/index.scss +0 -270
  123. package/playground/input/index.tsx +0 -112
  124. package/playground/number-inputs/index.tsx +0 -50
  125. package/playground/popovers/index.tsx +0 -70
  126. package/playground/radio-group/index.tsx +0 -69
  127. package/playground/select/index.tsx +0 -72
  128. package/playground/select-tags/index.tsx +0 -36
  129. package/playground/styles.scss +0 -2
  130. package/playground/switch/index.tsx +0 -44
  131. package/playground/tabs/index.tsx +0 -16
  132. package/playground/test.scss +0 -0
  133. package/playground/text-area/index.tsx +0 -17
  134. package/playground/text-input/index.tsx +0 -12
  135. package/playground/toaster/index.tsx +0 -156
  136. package/playground/tooltip/index.tsx +0 -26
  137. package/src/Button/index.tsx +0 -72
  138. package/src/ButtonGroup/index.tsx +0 -20
  139. package/src/Checkbox/index.tsx +0 -46
  140. package/src/Countdown/index.tsx +0 -54
  141. package/src/DateInput/index.tsx +0 -96
  142. package/src/DatePicker/Calendar.tsx +0 -157
  143. package/src/DatePicker/CalendarHeader.tsx +0 -139
  144. package/src/DatePicker/index.tsx +0 -177
  145. package/src/Dialog/index.tsx +0 -31
  146. package/src/DialogAlert/Alert.tsx +0 -78
  147. package/src/DialogAlert/Viewport.tsx +0 -52
  148. package/src/DialogAlert/index.tsx +0 -37
  149. package/src/Drawer/index.tsx +0 -46
  150. package/src/File/index.tsx +0 -60
  151. package/src/Form/index.tsx +0 -131
  152. package/src/Icon/index.tsx +0 -43
  153. package/src/LoadButton/index.tsx +0 -17
  154. package/src/NumberInput/index.tsx +0 -74
  155. package/src/OptionItem/OptionItem.tsx +0 -49
  156. package/src/OptionItem/OptionsList.tsx +0 -26
  157. package/src/Popover/index.tsx +0 -117
  158. package/src/Radio/index.tsx +0 -68
  159. package/src/Scrollable/ImitateScroll.tsx +0 -141
  160. package/src/Scrollable/index.tsx +0 -141
  161. package/src/Select/SelectInput.tsx +0 -131
  162. package/src/Select/index.tsx +0 -134
  163. package/src/SelectTags/index.tsx +0 -192
  164. package/src/Spinner/index.tsx +0 -19
  165. package/src/Stepper/index.tsx +0 -76
  166. package/src/Switch/index.tsx +0 -49
  167. package/src/Tabs/index.tsx +0 -89
  168. package/src/TextArea/index.tsx +0 -51
  169. package/src/Toaster/RemoveListener.tsx +0 -11
  170. package/src/Toaster/Toast.tsx +0 -69
  171. package/src/Toaster/Viewport.tsx +0 -117
  172. package/src/Toaster/index.tsx +0 -52
  173. package/src/Tooltip/index.tsx +0 -33
  174. package/src/__hooks/use-frooze-closing.ts +0 -51
  175. package/src/__hooks/use-loading.ts +0 -34
  176. package/src/__hooks/use-local-storage.ts +0 -19
  177. package/src/__hooks/use-popover-position.ts +0 -24
  178. package/src/__hooks/use-previos.ts +0 -25
  179. package/src/__hooks/use-resize.ts +0 -41
  180. package/src/__hooks/use-scrollbox.ts +0 -45
  181. package/src/__hooks/use-stepper-input.ts +0 -82
  182. package/src/__hooks/use-update.ts +0 -19
  183. package/src/__hooks/useCalendar.ts +0 -104
  184. package/src/__hooks/useCalendarOptions-copy.ts +0 -87
  185. package/src/__hooks/useCalendarOptions.ts +0 -68
  186. package/src/__libs/calendar.ts +0 -175
  187. package/src/__utils/utils.ts +0 -137
  188. package/src/index.ts +0 -36
  189. package/src/types.ts +0 -14
  190. package/tailwind.config.js +0 -91
  191. package/themes/classic/animations.scss +0 -179
  192. package/themes/classic/classic.scss +0 -493
  193. package/tsconfig.json +0 -27
  194. package/vite.build.ts +0 -35
  195. package/vite.config.ts +0 -33
  196. /package/{src → dist}/Button/Button.scss +0 -0
  197. /package/{src → dist}/ButtonGroup/ButtonGroup.scss +0 -0
  198. /package/{src → dist}/Checkbox/Checkbox.scss +0 -0
  199. /package/{src → dist}/DateInput/DateInput.scss +0 -0
  200. /package/{src → dist}/DatePicker/Calendar.scss +0 -0
  201. /package/{src → dist}/DatePicker/DatePicker.scss +0 -0
  202. /package/{src → dist}/Dialog/Dialog.scss +0 -0
  203. /package/{src → dist}/Dialog/Popup.scss +0 -0
  204. /package/{src → dist}/DialogAlert/Alert.scss +0 -0
  205. /package/{src → dist}/Drawer/Drawer.scss +0 -0
  206. /package/{src → dist}/Form/Form.scss +0 -0
  207. /package/{src → dist}/Form/Input.scss +0 -0
  208. /package/{src → dist}/Icon/icon.scss +0 -0
  209. /package/{src → dist}/OptionItem/Option.scss +0 -0
  210. /package/{src → dist}/Popover/Popover.scss +0 -0
  211. /package/{src → dist}/Radio/Radio.scss +0 -0
  212. /package/{src → dist}/Scrollable/Scrollable.scss +0 -0
  213. /package/{src → dist}/Select/Select.scss +0 -0
  214. /package/{src → dist}/SelectTags/SelectTags.scss +0 -0
  215. /package/{src → dist}/Spinner/Spinner.scss +0 -0
  216. /package/{src → dist}/Stepper/StepperInput.scss +0 -0
  217. /package/{src → dist}/Switch/Switch.scss +0 -0
  218. /package/{src → dist}/Tabs/Tabs.scss +0 -0
  219. /package/{src → dist}/TextArea/TextArea.scss +0 -0
  220. /package/{src → dist}/Toaster/Toaster.scss +0 -0
  221. /package/{src → dist}/Tooltip/Tooltip.scss +0 -0
  222. /package/{src/css.scss → dist/css-properties.scss} +0 -0
@@ -1,192 +0,0 @@
1
- import { useFroozeClosing } from '../__hooks/use-frooze-closing'
2
- import type { Option } from '../types'
3
- import { OptionItem, OptionsList, Popover } from '..'
4
- import { useMemo, useRef, useState } from 'react'
5
- import { Icon } from '../Icon'
6
- import { faChevronDown, faClose } from '@fortawesome/free-solid-svg-icons'
7
- import { attr, contains, getActiveElementByAnotherElement } from '@companix/utils-browser'
8
-
9
- export interface SelectTagsProps<T> {
10
- options: Option<T>[]
11
- onChange: (event: T[]) => void
12
- placeholder?: string
13
- value: T[]
14
- children?: React.ReactNode
15
- disabled?: boolean
16
- readOnly?: boolean
17
- closeAfterSelect?: boolean
18
- emptyText?: string
19
- size?: 'sm' | 'md' | 'lg'
20
- fill?: boolean
21
- }
22
-
23
- export const SelectTags = <T extends string | number>(props: SelectTagsProps<T>) => {
24
- const {
25
- options: optionsProp,
26
- closeAfterSelect,
27
- placeholder,
28
- onChange,
29
- emptyText = 'Ничего не найдено',
30
- readOnly,
31
- size = 'md',
32
- value: values,
33
- disabled
34
- } = props
35
-
36
- const [inputValue, setInputValue] = useState('')
37
- const inputRef = useRef<HTMLInputElement>(null)
38
- const listboxRef = useRef<HTMLDivElement>(null)
39
- const { popoverRef, froozePopoverPosition, handleAnimationEnd } = useFroozeClosing()
40
-
41
- const store = useMemo(() => {
42
- const store = {} as { [value in T]: Option<T> }
43
-
44
- optionsProp.forEach((option) => {
45
- store[option.value] = option
46
- })
47
-
48
- return store
49
- }, [optionsProp])
50
-
51
- const add = (value: T) => {
52
- if (values.includes(value)) {
53
- return [...values]
54
- }
55
-
56
- return [...values, value]
57
- }
58
-
59
- const remove = (value: T) => {
60
- return values.filter((item) => value !== item)
61
- }
62
-
63
- const handleSelect = (value: T[], close: () => void) => {
64
- if (closeAfterSelect) {
65
- froozePopoverPosition()
66
- onChange(value)
67
- close()
68
- } else {
69
- onChange(value)
70
- }
71
- }
72
-
73
- const options = useMemo(() => {
74
- if (!inputValue.trim()) {
75
- return optionsProp
76
- }
77
-
78
- return optionsProp.filter(({ title }) => {
79
- const normalizedTitle = title.toLowerCase()
80
- const normalizedQuery = inputValue.trim().toLowerCase()
81
-
82
- return normalizedTitle.indexOf(normalizedQuery) >= 0
83
- })
84
- }, [inputValue, optionsProp])
85
-
86
- const handleRootClick = (event: React.MouseEvent) => {
87
- if (disabled) return
88
-
89
- // Предотвращаем закрытие Popover при клике на форму
90
- if (popoverRef.current && popoverRef.current.getAttribute('data-state') === 'open') {
91
- event.preventDefault()
92
- }
93
-
94
- const activeElement = getActiveElementByAnotherElement(event.currentTarget)
95
-
96
- if (event.defaultPrevented || contains(event.currentTarget, activeElement)) {
97
- return
98
- }
99
-
100
- if (inputRef.current) {
101
- inputRef.current.focus()
102
- }
103
- }
104
-
105
- const handleRootMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
106
- // Когда клик в сам инпут, не нужно делать preventDefault, так как не будет работать выделение текста
107
- if (e.target === inputRef.current) {
108
- return
109
- }
110
- // Делаем preventDefault
111
- e.preventDefault()
112
- }
113
-
114
- const handleRemove = (e: React.MouseEvent, value: T) => {
115
- e.stopPropagation()
116
- onChange(remove(value))
117
- }
118
-
119
- // const
120
-
121
- return (
122
- <Popover
123
- minimal
124
- ref={popoverRef}
125
- sideOffset={0}
126
- matchTarget="width"
127
- onAnimationEnd={handleAnimationEnd}
128
- onOpenAutoFocus={(e) => e.preventDefault()}
129
- onCloseAutoFocus={(e) => e.preventDefault()}
130
- content={({ close }) => (
131
- <OptionsList maxHeight={300}>
132
- {options.length === 0 && <div className="select-tags-empty">{emptyText}</div>}
133
- {options.map(({ value, title, icon }, i) => (
134
- <OptionItem
135
- key={`option-item-${value}-${i}`}
136
- active={values.includes(value)}
137
- onClick={() => handleSelect(add(value), close)}
138
- title={title}
139
- icon={icon}
140
- />
141
- ))}
142
- </OptionsList>
143
- )}
144
- >
145
- <div
146
- className="form"
147
- onClick={handleRootClick}
148
- onMouseDown={handleRootMouseDown}
149
- data-size={size}
150
- >
151
- <div className="select-tags-container">
152
- <div className="select-tags">
153
- {values.length > 0 && (
154
- <div
155
- className="tag-container"
156
- ref={listboxRef}
157
- role="listbox"
158
- data-readonly={attr(readOnly)}
159
- >
160
- {values.map((value, i) => (
161
- <div key={`tag-option-${value}-${i}`} className="tag">
162
- <span className="tag-name">{store[value].title}</span>
163
- <button className="tag-close-button" onClick={(e) => handleRemove(e, value)}>
164
- <Icon className="tag-close-icon" icon={faClose} size="xxxs" />
165
- </button>
166
- </div>
167
- ))}
168
- </div>
169
- )}
170
- {(!readOnly || values.length === 0) && (
171
- <input
172
- ref={inputRef}
173
- type="text"
174
- autoCapitalize="none"
175
- autoComplete="off"
176
- autoCorrect="off"
177
- className="form-input"
178
- spellCheck={false}
179
- value={inputValue}
180
- disabled={disabled}
181
- readOnly={readOnly}
182
- placeholder={placeholder}
183
- onChange={({ target }) => setInputValue(target.value)}
184
- />
185
- )}
186
- </div>
187
- <Icon className="expand-icon" icon={faChevronDown} size="xxxs" />
188
- </div>
189
- </div>
190
- </Popover>
191
- )
192
- }
@@ -1,19 +0,0 @@
1
- import './Spinner.scss'
2
- import cn from 'classnames'
3
-
4
- interface Props {
5
- size?: number
6
- width?: number
7
- color?: string
8
- className?: string
9
- }
10
-
11
- export const Spinner = ({ size = 40, className, width = 4, color = 'inherit' }: Props) => {
12
- return (
13
- <div
14
- style={{ width: `${size}px`, height: `${size}px`, color, borderWidth: `${width}px` }}
15
- className={cn('spinner-border', className)}
16
- role="status"
17
- />
18
- )
19
- }
@@ -1,76 +0,0 @@
1
- import './StepperInput.scss'
2
-
3
- import { Form } from '../Form'
4
- import { useStepperInput, StepperInputOptions } from '../__hooks/use-stepper-input'
5
- import { usePress } from '@react-aria/interactions'
6
- import { Button } from '../Button'
7
- import { attr } from '@companix/utils-browser'
8
- import { Icon } from '../Icon'
9
- import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons'
10
-
11
- interface StepperInputProps extends StepperInputOptions {
12
- buttons?: boolean
13
- placeholder?: string
14
- inputStyle?: React.CSSProperties
15
- }
16
-
17
- export const StepperInput = ({ inputStyle, placeholder, buttons, ...options }: StepperInputProps) => {
18
- const { inputRef, increment, decrement, handleChange, value } = useStepperInput(options)
19
-
20
- return (
21
- <div className="number-input-container">
22
- <Form
23
- ref={inputRef}
24
- placeholder={placeholder}
25
- style={inputStyle}
26
- value={value}
27
- onChange={handleChange}
28
- />
29
- {buttons && <Stepper increment={increment} decrement={decrement} />}
30
- </div>
31
- )
32
- }
33
-
34
- interface StepperProps {
35
- increment: () => void
36
- decrement: () => void
37
- }
38
-
39
- const Stepper = ({ increment, decrement }: StepperProps) => {
40
- return (
41
- <div className="number-stepper">
42
- <SlepButton slot="increment" onClick={increment}>
43
- <Icon size="xxs" icon={faChevronUp} />
44
- </SlepButton>
45
- <div className="number-stepper-splitter" />
46
- <SlepButton slot="decrement" onClick={decrement}>
47
- <Icon size="xxs" icon={faChevronDown} />
48
- </SlepButton>
49
- </div>
50
- )
51
- }
52
-
53
- interface ButtonProps {
54
- children: React.ReactNode
55
- slot: string
56
- onClick: () => void
57
- }
58
-
59
- const SlepButton = ({ children, slot, onClick }: ButtonProps) => {
60
- const { pressProps, isPressed } = usePress({ onClick, preventFocusOnPress: true })
61
- const { onBeforeInput, ...rest } = pressProps
62
-
63
- return (
64
- <Button
65
- {...rest}
66
- onBeforeInput={onBeforeInput as any}
67
- data-slot={slot}
68
- data-size={undefined}
69
- data-pressed={attr(isPressed)}
70
- style={{ border: 'none' }}
71
- className="number-stepper-slot"
72
- >
73
- {children}
74
- </Button>
75
- )
76
- }
@@ -1,49 +0,0 @@
1
- import * as SwitchPrimitive from '@radix-ui/react-switch'
2
- import { attr } from '@companix/utils-browser'
3
- import { useId } from 'react'
4
-
5
- export interface SwitchProps {
6
- checked: boolean
7
- onCheckedChange: (checked: boolean) => void
8
- label?: React.ReactNode
9
- disabled?: boolean
10
- checkedIcon?: React.ReactNode
11
- uncheckedIcon?: React.ReactNode
12
- }
13
-
14
- const Switch = (props: SwitchProps) => {
15
- const { checked, disabled, onCheckedChange, uncheckedIcon, checkedIcon, label } = props
16
- const id = useId()
17
-
18
- return (
19
- <div className="switch" data-disabled={attr(disabled)}>
20
- <SwitchPrimitive.Root
21
- className="switch-track"
22
- checked={checked}
23
- onCheckedChange={onCheckedChange}
24
- disabled={disabled}
25
- id={id}
26
- >
27
- <SwitchPrimitive.Thumb className="switch-thumb">
28
- {uncheckedIcon && (
29
- <span className="switch-thumb-icon" data-visible={attr(!checked)}>
30
- {uncheckedIcon}
31
- </span>
32
- )}
33
- {checkedIcon && (
34
- <span className="switch-thumb-icon" data-visible={attr(checked)}>
35
- {checkedIcon}
36
- </span>
37
- )}
38
- </SwitchPrimitive.Thumb>
39
- </SwitchPrimitive.Root>
40
- {label && (
41
- <label className="switch-label" htmlFor={id} data-disabled={disabled}>
42
- {label}
43
- </label>
44
- )}
45
- </div>
46
- )
47
- }
48
-
49
- export { Switch }
@@ -1,89 +0,0 @@
1
- import * as RadixTabs from '@radix-ui/react-tabs'
2
- import { createContext, useContext, useEffect, useId, useRef, useState } from 'react'
3
-
4
- interface Props {
5
- children: React.ReactNode
6
- onChange: (value: string) => void
7
- value: string
8
- }
9
-
10
- const TabsContext = createContext({ baseId: '', listRef: {} as React.RefObject<HTMLDivElement> })
11
-
12
- const makeTriggerId = (baseId: string, value: string) => {
13
- return `radix-${baseId}-trigger-${value}`
14
- }
15
-
16
- export const Tabs = ({ children, value, onChange }: Props) => {
17
- const listRef = useRef<HTMLDivElement>(null)
18
- const baseId = useId()
19
-
20
- return (
21
- <RadixTabs.Root value={value} onValueChange={onChange}>
22
- <TabsContext.Provider value={{ baseId, listRef }}>
23
- <RadixTabs.List className="tabs" ref={listRef}>
24
- <TabIndicator value={value} />
25
- {children}
26
- </RadixTabs.List>
27
- </TabsContext.Provider>
28
- </RadixTabs.Root>
29
- )
30
- }
31
-
32
- const TabIndicator = ({ value }: { value: string }) => {
33
- const [styles, setStyles] = useState<React.CSSProperties>({})
34
- const { baseId, listRef } = useContext(TabsContext)
35
-
36
- useEffect(() => {
37
- const state = { observer: null as null | ResizeObserver }
38
-
39
- if (listRef.current) {
40
- const tabIdSelector = `.tab[id="${makeTriggerId(baseId, value)}"]`
41
- const selectedTabElement = listRef.current.querySelector<HTMLElement>(tabIdSelector)
42
-
43
- if (selectedTabElement != null) {
44
- state.observer = new ResizeObserver(() => {
45
- const { clientHeight, clientWidth, offsetLeft, offsetTop } = selectedTabElement
46
-
47
- setStyles({
48
- height: clientHeight,
49
- transform: `translateX(${Math.floor(offsetLeft)}px) translateY(${Math.floor(offsetTop)}px)`,
50
- width: clientWidth
51
- })
52
- })
53
-
54
- state.observer.observe(selectedTabElement)
55
- } else {
56
- setStyles({ display: 'none' })
57
- }
58
- }
59
-
60
- return () => {
61
- if (state.observer) {
62
- state.observer.disconnect()
63
- }
64
- }
65
- }, [value])
66
-
67
- return (
68
- <div className="tab-indicator-container" style={styles}>
69
- <div className="tab-indicator" />
70
- </div>
71
- )
72
- }
73
-
74
- interface TabProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
75
- value: string
76
- }
77
-
78
- const Tab = ({ children, value, ...restProps }: TabProps) => {
79
- const { baseId } = useContext(TabsContext)
80
- const id = makeTriggerId(baseId, value)
81
-
82
- return (
83
- <RadixTabs.Trigger {...restProps} id={id} className="tab" value={value}>
84
- {children}
85
- </RadixTabs.Trigger>
86
- )
87
- }
88
-
89
- Tabs.Tab = Tab
@@ -1,51 +0,0 @@
1
- import { useResizeTextarea } from '../__hooks/use-resize'
2
- import { attr, callMultiple } from '@companix/utils-browser'
3
- import { useEffect } from 'react'
4
-
5
- interface TextAreaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
6
- /**
7
- * Свойство управляющее автоматическим изменением высоты компонента.
8
- */
9
- grow?: boolean
10
- /**
11
- * Обработчик, срабатывающий при изменении размера компонента.
12
- */
13
- onResize?: (el: HTMLTextAreaElement) => void
14
- fill?: boolean
15
- }
16
-
17
- export const TextArea = ({
18
- onResize,
19
- grow = false,
20
- value,
21
- onChange,
22
- disabled,
23
- required,
24
- rows = 2,
25
- fill = false,
26
- ...textAreaProps
27
- }: TextAreaProps) => {
28
- const [refResizeTextarea, resize] = useResizeTextarea(onResize, grow)
29
-
30
- useEffect(resize, [resize, value])
31
-
32
- return (
33
- <div
34
- className="form form-textarea"
35
- data-required={attr(required)}
36
- data-disabled={attr(disabled)}
37
- data-fill={attr(fill)}
38
- >
39
- <textarea
40
- className="form-input"
41
- data-grow={attr(grow)}
42
- value={value}
43
- ref={refResizeTextarea}
44
- rows={rows}
45
- disabled={disabled}
46
- onChange={callMultiple(onChange, resize)}
47
- {...textAreaProps}
48
- />
49
- </div>
50
- )
51
- }
@@ -1,11 +0,0 @@
1
- import { useEffect } from 'react'
2
-
3
- export const RemoveListener = ({ callback }: { callback?: () => void }) => {
4
- useEffect(() => {
5
- return () => {
6
- callback?.()
7
- }
8
- }, [])
9
-
10
- return null
11
- }
@@ -1,69 +0,0 @@
1
- import * as ToasterPrimitive from '@radix-ui/react-toast'
2
- import { attr } from '@companix/utils-browser'
3
- import { useEffect, useLayoutEffect, useRef, useState } from 'react'
4
- import { ToastOptions } from '.'
5
- import { RemoveListener } from './RemoveListener'
6
-
7
- interface ToastProps extends ToastOptions {
8
- onRemoved: () => void
9
- onRemoving: () => void
10
- onInitialized: (ref: HTMLLIElement) => void
11
- closeIcon?: React.ReactNode
12
- }
13
-
14
- export const Toast = (options: ToastProps) => {
15
- const [mounted, setMounted] = useState(false)
16
-
17
- const ref = useRef<HTMLLIElement>(null)
18
-
19
- const {
20
- appearance = 'neutral',
21
- icon,
22
- title,
23
- description,
24
- duration,
25
- closeIcon,
26
- onRemoving,
27
- onRemoved,
28
- onInitialized
29
- } = options
30
-
31
- useEffect(() => {
32
- setMounted(true)
33
- }, [])
34
-
35
- useLayoutEffect(() => {
36
- if (ref.current) {
37
- onInitialized(ref.current)
38
- }
39
- }, [])
40
-
41
- return (
42
- <ToasterPrimitive.Root
43
- ref={ref}
44
- data-expanded
45
- data-appearance={appearance}
46
- data-mounted={attr(mounted)}
47
- className="toaster"
48
- duration={duration}
49
- >
50
- <RemoveListener callback={onRemoved} />
51
- {icon && <div className="toaster-icon">{icon}</div>}
52
- <div className="toaster-content">
53
- {title && <ToasterPrimitive.Title className="toaster-title">{title}</ToasterPrimitive.Title>}
54
- {description && (
55
- <ToasterPrimitive.Description className="toaster-description">
56
- {description}
57
- </ToasterPrimitive.Description>
58
- )}
59
- </div>
60
- <ToasterPrimitive.Close className="toaster-close" onClick={onRemoving}>
61
- {closeIcon ?? (
62
- <svg viewBox="0 0 16 16" fill="currentColor">
63
- <path d="M2.96967 2.96967C3.26256 2.67678 3.73744 2.67678 4.03033 2.96967L8 6.939L11.9697 2.96967C12.2626 2.67678 12.7374 2.67678 13.0303 2.96967C13.3232 3.26256 13.3232 3.73744 13.0303 4.03033L9.061 8L13.0303 11.9697C13.2966 12.2359 13.3208 12.6526 13.1029 12.9462L13.0303 13.0303C12.7374 13.3232 12.2626 13.3232 11.9697 13.0303L8 9.061L4.03033 13.0303C3.73744 13.3232 3.26256 13.3232 2.96967 13.0303C2.67678 12.7374 2.67678 12.2626 2.96967 11.9697L6.939 8L2.96967 4.03033C2.7034 3.76406 2.6792 3.3474 2.89705 3.05379L2.96967 2.96967Z" />
64
- </svg>
65
- )}
66
- </ToasterPrimitive.Close>
67
- </ToasterPrimitive.Root>
68
- )
69
- }
@@ -1,117 +0,0 @@
1
- import * as ToasterPrimitive from '@radix-ui/react-toast'
2
- import { varToStyle } from '@companix/utils-browser'
3
- import { useCallback, useMemo, useState, useImperativeHandle, forwardRef } from 'react'
4
- import { Toast } from './Toast'
5
- import { InnerToast } from '.'
6
-
7
- enum SwipesDirections {
8
- 'top-center' = 'up',
9
- 'top-left' = 'left',
10
- 'top-right' = 'right',
11
- 'bottom-center' = 'down',
12
- 'bottom-left' = 'left',
13
- 'bottom-right' = 'right'
14
- }
15
-
16
- export interface ViewportProps {
17
- side?: 'top' | 'bottom'
18
- align?: 'center' | 'left' | 'right'
19
- gap?: number // gap between toasts
20
- swipeThreshold?: number
21
- duration?: number
22
- closeIcon?: React.ReactNode
23
- }
24
-
25
- export interface ViewportRef {
26
- addToast: (toast: InnerToast) => void
27
- }
28
-
29
- export const Viewport = forwardRef<ViewportRef, ViewportProps>((props, ref) => {
30
- const { side = 'top', align = 'center', gap = 14, duration, swipeThreshold, closeIcon } = props
31
- const [toasters, setToasters] = useState<InnerToast[]>([])
32
-
33
- const refs = useMemo((): { [id: string]: HTMLLIElement } => {
34
- return {}
35
- }, [])
36
-
37
- useImperativeHandle(
38
- ref,
39
- () => {
40
- return {
41
- addToast: (toast) => {
42
- setToasters((state) => [...state, toast])
43
- }
44
- }
45
- },
46
- []
47
- )
48
-
49
- const applyOffsets = useCallback((toasters: InnerToast[]) => {
50
- toasters.forEach(({ id }, index) => {
51
- let offset = 0
52
-
53
- for (let i = index + 1; i < toasters.length; i++) {
54
- if (refs[toasters[i].id]) {
55
- offset += refs[toasters[i].id].clientHeight + gap
56
- }
57
- }
58
-
59
- if (refs[id]) {
60
- refs[id].style.setProperty('--offset', `${offset}px`)
61
- }
62
- })
63
- }, [])
64
-
65
- const handleClose = (id: string) => {
66
- setToasters((state) => {
67
- const nextState = [...state]
68
- const index = nextState.findIndex((item) => item.id === id)
69
-
70
- if (index !== -1) {
71
- nextState.splice(index, 1)
72
- }
73
-
74
- return nextState
75
- })
76
- }
77
-
78
- return (
79
- <ToasterPrimitive.Provider
80
- duration={duration}
81
- swipeThreshold={swipeThreshold}
82
- swipeDirection={SwipesDirections[`${side}-${align}`]}
83
- >
84
- {toasters.map(({ id, ...toast }) => (
85
- <Toast
86
- {...toast}
87
- key={`toaster-${id}`}
88
- closeIcon={closeIcon}
89
- onInitialized={(ref) => {
90
- refs[id] = ref
91
- applyOffsets(toasters)
92
- }}
93
- onRemoving={() => {
94
- delete refs[id]
95
- applyOffsets(toasters)
96
- }}
97
- onRemoved={() => {
98
- if (refs[id]) {
99
- // Если коллбек onRemoved вызвается при истечении duration,
100
- // мы не перехватываем событие onRemoving и не изменяем позиции текущих тостов
101
- // (автоматическое закрытие тостов всегда происходит в порядке открытия)
102
- delete refs[id]
103
- }
104
-
105
- handleClose(id)
106
- }}
107
- />
108
- ))}
109
- <ToasterPrimitive.Viewport
110
- data-side={side}
111
- data-align={align}
112
- className="toaster-viewport"
113
- style={varToStyle({ '--toasters-gap': `${gap}px` })}
114
- />
115
- </ToasterPrimitive.Provider>
116
- )
117
- })