@scaleflex/ui-tw 0.0.26 → 0.0.27
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.
- package/form/components/form-select-field.component.d.ts +5 -0
- package/form/components/form-select-field.component.js +86 -0
- package/form/form.types.d.ts +30 -0
- package/form/form.utils.d.ts +2 -0
- package/form/form.utils.js +3 -0
- package/form/index.d.ts +3 -0
- package/form/index.js +4 -1
- package/input/input.component.js +4 -2
- package/input/input.constants.d.ts +1 -1
- package/input/input.constants.js +1 -1
- package/input/input.utils.d.ts +1 -0
- package/input/input.utils.js +3 -0
- package/package.json +3 -2
- package/select/components/select-icon.d.ts +2 -0
- package/select/components/select-icon.js +22 -0
- package/select/index.d.ts +1 -0
- package/select/index.js +1 -0
- package/select/select.component.d.ts +14 -0
- package/select/select.component.js +165 -0
- package/select/select.constants.d.ts +5 -0
- package/select/select.constants.js +3 -0
- package/select/select.types.d.ts +22 -0
- package/select/select.types.js +1 -0
- package/select/select.utils.d.ts +3 -0
- package/select/select.utils.js +28 -0
- package/styles/variables.css +2 -0
- package/tooltip/tooltip.component.js +3 -7
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FieldValues, Path } from 'react-hook-form';
|
|
3
|
+
import { FormSelectFieldProps } from '../form.types';
|
|
4
|
+
declare function FormSelectField<TFieldValues extends FieldValues, TName extends Path<TFieldValues>>({ selectProps, ...rest }: FormSelectFieldProps<TFieldValues, TName>): React.JSX.Element;
|
|
5
|
+
export { FormSelectField };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["icon", "placeholder", "options"],
|
|
4
|
+
_excluded2 = ["selectProps"];
|
|
5
|
+
import { isOptionGroup, useFormField } from '@scaleflex/ui-tw/form';
|
|
6
|
+
import { FormFieldGroup } from '@scaleflex/ui-tw/form';
|
|
7
|
+
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from '@scaleflex/ui-tw/select';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
function FormSelectInner(_ref) {
|
|
10
|
+
var field = _ref.field,
|
|
11
|
+
args = _ref.args,
|
|
12
|
+
selectProps = _ref.selectProps,
|
|
13
|
+
readOnly = _ref.readOnly,
|
|
14
|
+
disabled = _ref.disabled,
|
|
15
|
+
className = _ref.className;
|
|
16
|
+
var _useFormField = useFormField(),
|
|
17
|
+
error = _useFormField.error,
|
|
18
|
+
formItemId = _useFormField.formItemId;
|
|
19
|
+
var _ref2 = selectProps || {},
|
|
20
|
+
icon = _ref2.icon,
|
|
21
|
+
placeholder = _ref2.placeholder,
|
|
22
|
+
options = _ref2.options,
|
|
23
|
+
restSelectProps = _objectWithoutProperties(_ref2, _excluded);
|
|
24
|
+
return /*#__PURE__*/React.createElement(Select, _extends({
|
|
25
|
+
onValueChange: readOnly ? undefined : field.onChange,
|
|
26
|
+
defaultValue: field.value,
|
|
27
|
+
disabled: disabled || readOnly
|
|
28
|
+
}, restSelectProps), /*#__PURE__*/React.createElement(SelectTrigger, {
|
|
29
|
+
id: formItemId,
|
|
30
|
+
"aria-invalid": !!error,
|
|
31
|
+
size: args === null || args === void 0 ? void 0 : args.size,
|
|
32
|
+
readOnly: readOnly,
|
|
33
|
+
className: className,
|
|
34
|
+
icon: icon
|
|
35
|
+
}, /*#__PURE__*/React.createElement(SelectValue, {
|
|
36
|
+
placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : 'Select'
|
|
37
|
+
})), /*#__PURE__*/React.createElement(SelectContent, null, options === null || options === void 0 ? void 0 : options.map(function (option, groupIndex) {
|
|
38
|
+
if (isOptionGroup(option)) {
|
|
39
|
+
return /*#__PURE__*/React.createElement(SelectGroup, {
|
|
40
|
+
key: groupIndex
|
|
41
|
+
}, option.label && /*#__PURE__*/React.createElement(SelectLabel, {
|
|
42
|
+
size: args === null || args === void 0 ? void 0 : args.size
|
|
43
|
+
}, option.label), option.options.map(function (_ref3) {
|
|
44
|
+
var label = _ref3.label,
|
|
45
|
+
value = _ref3.value,
|
|
46
|
+
disabled = _ref3.disabled,
|
|
47
|
+
icon = _ref3.icon,
|
|
48
|
+
tooltip = _ref3.tooltip;
|
|
49
|
+
return /*#__PURE__*/React.createElement(SelectItem, {
|
|
50
|
+
key: value,
|
|
51
|
+
value: value,
|
|
52
|
+
disabled: disabled,
|
|
53
|
+
size: args === null || args === void 0 ? void 0 : args.size,
|
|
54
|
+
icon: icon,
|
|
55
|
+
tooltip: tooltip,
|
|
56
|
+
isGroup: !!option.label
|
|
57
|
+
}, label);
|
|
58
|
+
}), groupIndex !== options.length - 1 && /*#__PURE__*/React.createElement(SelectSeparator, null));
|
|
59
|
+
}
|
|
60
|
+
return /*#__PURE__*/React.createElement(SelectGroup, {
|
|
61
|
+
key: "default"
|
|
62
|
+
}, /*#__PURE__*/React.createElement(SelectItem, {
|
|
63
|
+
value: option.value,
|
|
64
|
+
disabled: option.disabled,
|
|
65
|
+
size: args === null || args === void 0 ? void 0 : args.size,
|
|
66
|
+
icon: option.icon,
|
|
67
|
+
tooltip: option.tooltip
|
|
68
|
+
}, option.label));
|
|
69
|
+
})));
|
|
70
|
+
}
|
|
71
|
+
function FormSelectField(_ref4) {
|
|
72
|
+
var selectProps = _ref4.selectProps,
|
|
73
|
+
rest = _objectWithoutProperties(_ref4, _excluded2);
|
|
74
|
+
var readOnly = rest.readOnly,
|
|
75
|
+
disabled = rest.disabled;
|
|
76
|
+
return /*#__PURE__*/React.createElement(FormFieldGroup, rest, function (field, args) {
|
|
77
|
+
return /*#__PURE__*/React.createElement(FormSelectInner, {
|
|
78
|
+
field: field,
|
|
79
|
+
args: args,
|
|
80
|
+
selectProps: selectProps,
|
|
81
|
+
readOnly: readOnly,
|
|
82
|
+
disabled: disabled
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export { FormSelectField };
|
package/form/form.types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InputProps } from '@scaleflex/ui-tw/input';
|
|
2
|
+
import { SelectProps } from '@scaleflex/ui-tw/select/select.types';
|
|
2
3
|
import { SwitchProps } from '@scaleflex/ui-tw/switch/switch.types';
|
|
3
4
|
import { TextareaProps } from '@scaleflex/ui-tw/textarea';
|
|
4
5
|
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
@@ -45,3 +46,32 @@ export type FormInputFieldProps<TFieldValues extends FieldValues, TName extends
|
|
|
45
46
|
export type FormTextareaFieldProps<TFieldValues extends FieldValues, TName extends Path<TFieldValues>> = Omit<FormFieldGroupProps<TFieldValues, TName>, 'children'> & {
|
|
46
47
|
textareaProps?: TextareaProps;
|
|
47
48
|
};
|
|
49
|
+
export interface FlatOption {
|
|
50
|
+
label: ReactElement | string;
|
|
51
|
+
value: string;
|
|
52
|
+
disabled?: boolean;
|
|
53
|
+
icon?: ReactElement;
|
|
54
|
+
tooltip?: ReactElement | string;
|
|
55
|
+
}
|
|
56
|
+
export interface OptionGroup {
|
|
57
|
+
label?: ReactElement | string;
|
|
58
|
+
options: FlatOption[];
|
|
59
|
+
}
|
|
60
|
+
export type SelectOption = FlatOption | OptionGroup;
|
|
61
|
+
export type FormSelectProps = SelectProps & {
|
|
62
|
+
options: SelectOption[];
|
|
63
|
+
placeholder?: string;
|
|
64
|
+
icon?: ReactElement;
|
|
65
|
+
};
|
|
66
|
+
export type FormSelectFieldProps<TFieldValues extends FieldValues, TName extends Path<TFieldValues>> = Omit<FormFieldGroupProps<TFieldValues, TName>, 'children'> & {
|
|
67
|
+
icon?: ReactElement;
|
|
68
|
+
selectProps?: FormSelectProps;
|
|
69
|
+
};
|
|
70
|
+
export interface FormSelectInnerProps<TFieldValues extends FieldValues, TName extends Path<TFieldValues>> {
|
|
71
|
+
field: ControllerRenderProps<TFieldValues, TName>;
|
|
72
|
+
args: FormFieldArgs | undefined;
|
|
73
|
+
selectProps?: FormSelectProps;
|
|
74
|
+
readOnly?: boolean;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
className?: string;
|
|
77
|
+
}
|
package/form/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, useFormField, } from './form.component';
|
|
2
|
+
export { isOptionGroup } from './form.utils';
|
|
3
|
+
export { SelectOption, FlatOption, OptionGroup } from './form.types';
|
|
2
4
|
export { FormFieldGroup } from './components/form-field-group.component';
|
|
3
5
|
export { FormInputField } from './components/form-input-field.component';
|
|
4
6
|
export { FormPasswordField } from './components/form-password-field.component';
|
|
5
7
|
export { FormTextareaField } from './components/form-textarea-field.component';
|
|
6
8
|
export { FormSwitchField } from './components/form-switch-field.component';
|
|
9
|
+
export { FormSelectField } from './components/form-select-field.component';
|
package/form/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, useFormField } from './form.component';
|
|
2
|
+
export { isOptionGroup } from './form.utils';
|
|
3
|
+
export { SelectOption, FlatOption, OptionGroup } from './form.types';
|
|
2
4
|
export { FormFieldGroup } from './components/form-field-group.component';
|
|
3
5
|
export { FormInputField } from './components/form-input-field.component';
|
|
4
6
|
export { FormPasswordField } from './components/form-password-field.component';
|
|
5
7
|
export { FormTextareaField } from './components/form-textarea-field.component';
|
|
6
|
-
export { FormSwitchField } from './components/form-switch-field.component';
|
|
8
|
+
export { FormSwitchField } from './components/form-switch-field.component';
|
|
9
|
+
export { FormSelectField } from './components/form-select-field.component';
|
package/input/input.component.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
4
|
var _excluded = ["className", "type", "size", "disabled", "readOnly"];
|
|
5
|
+
import { getBaseInputClasses } from '@scaleflex/ui-tw/input/input.utils';
|
|
4
6
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
5
7
|
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
6
8
|
import { cva } from 'class-variance-authority';
|
|
@@ -30,10 +32,10 @@ function Input(_ref) {
|
|
|
30
32
|
"data-slot": "input",
|
|
31
33
|
disabled: disabled,
|
|
32
34
|
readOnly: readOnly,
|
|
33
|
-
className: cn(
|
|
35
|
+
className: cn.apply(void 0, ['flex w-full min-w-0'].concat(_toConsumableArray(getBaseInputClasses()), ['read-only:bg-secondary read-only:text-foreground read-only:cursor-default', 'selection:bg-primary selection:text-primary-foreground', inputVariants({
|
|
34
36
|
size: size,
|
|
35
37
|
className: className
|
|
36
|
-
}))
|
|
38
|
+
})]))
|
|
37
39
|
}, props));
|
|
38
40
|
}
|
|
39
41
|
export { Input, inputVariants };
|
package/input/input.constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
3
|
-
export var inputSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'py-2 px-3 text-sm
|
|
3
|
+
export var inputSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'py-2 px-3 h-8 text-sm'), FormSize.Md, 'py-3 px-4 h-10 text-base '), FormSize.Lg, 'py-3 px-4 h-12 text-lg ');
|
|
4
4
|
export var InputType = {
|
|
5
5
|
Text: 'text',
|
|
6
6
|
Email: 'email',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getBaseInputClasses: () => string[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export var getBaseInputClasses = function getBaseInputClasses() {
|
|
2
|
+
return ['rounded-md border shadow-xs transition-[color,box-shadow] outline-none', 'border-input text-foreground bg-background', 'placeholder:text-muted-foreground/80 hover:border-secondary-foreground/50', 'disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50', 'focus-visible:border-secondary-foreground/50 focus-visible:ring-ring ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none', 'aria-invalid:ring-destructive/20 aria-invalid:border-destructive hover:aria-invalid:border-destructive/60 focus-visible:aria-invalid:border-destructive', 'focus-visible:group-data-[highlight=true]:border-warning group-data-[highlight=true]:border-warning hover:group-data-[highlight=true]:border-warning/60 group-data-[highlight=true]:focus-visible:ring-warning/20'];
|
|
3
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/ui-tw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"author": "scaleflex",
|
|
5
5
|
"repository": "github:scaleflex/ui",
|
|
6
6
|
"homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@popperjs/core": "^2.6.0",
|
|
16
16
|
"@radix-ui/react-label": "^2.1.6",
|
|
17
|
+
"@radix-ui/react-select": "^2.2.4",
|
|
17
18
|
"@radix-ui/react-separator": "^1.1.6",
|
|
18
19
|
"@radix-ui/react-slot": "^1.1.2",
|
|
19
20
|
"@radix-ui/react-switch": "^1.0.1",
|
|
20
21
|
"@radix-ui/react-tooltip": "^1.2.6",
|
|
21
|
-
"@scaleflex/icons-tw": "^0.0.
|
|
22
|
+
"@scaleflex/icons-tw": "^0.0.27",
|
|
22
23
|
"@types/lodash.merge": "^4.6.9",
|
|
23
24
|
"class-variance-authority": "^0.7.1",
|
|
24
25
|
"lodash.merge": "^4.6.2",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getIconSizeInRem } from '@scaleflex/ui-tw/button/button.utils';
|
|
2
|
+
import { getIconMarginRightInRem } from '@scaleflex/ui-tw/select/select.utils';
|
|
3
|
+
import { cloneElement, useMemo } from 'react';
|
|
4
|
+
export var SelectIcon = function SelectIcon(props) {
|
|
5
|
+
var size = props.size,
|
|
6
|
+
icon = props.icon;
|
|
7
|
+
var sizeInRem = useMemo(function () {
|
|
8
|
+
return getIconSizeInRem(size);
|
|
9
|
+
}, [size]);
|
|
10
|
+
var marginRight = useMemo(function () {
|
|
11
|
+
return getIconMarginRightInRem(size);
|
|
12
|
+
}, [size]);
|
|
13
|
+
if (!icon) return null;
|
|
14
|
+
return /*#__PURE__*/cloneElement(icon, {
|
|
15
|
+
size: sizeInRem,
|
|
16
|
+
style: {
|
|
17
|
+
width: sizeInRem,
|
|
18
|
+
height: sizeInRem,
|
|
19
|
+
marginRight: marginRight
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Select, SelectGroup, SelectItem, SelectLabel, SelectContent, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectValue, SelectTrigger, } from './select.component';
|
package/select/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Select, SelectGroup, SelectItem, SelectLabel, SelectContent, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectValue, SelectTrigger } from './select.component';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
2
|
+
import { SelectItemProps, SelectLabelProps, SelectTriggerProps } from '@scaleflex/ui-tw/select/select.types';
|
|
3
|
+
import React, { ComponentProps } from 'react';
|
|
4
|
+
declare function Select({ ...props }: ComponentProps<typeof SelectPrimitive.Root>): React.JSX.Element;
|
|
5
|
+
declare function SelectGroup({ ...props }: ComponentProps<typeof SelectPrimitive.Group>): React.JSX.Element;
|
|
6
|
+
declare function SelectValue({ ...props }: ComponentProps<typeof SelectPrimitive.Value>): React.JSX.Element;
|
|
7
|
+
declare function SelectTrigger({ className, size, children, readOnly, icon, ...props }: SelectTriggerProps): React.JSX.Element;
|
|
8
|
+
declare function SelectContent({ className, children, position, ...props }: ComponentProps<typeof SelectPrimitive.Content>): React.JSX.Element;
|
|
9
|
+
declare function SelectLabel({ className, size, ...props }: SelectLabelProps): React.JSX.Element;
|
|
10
|
+
declare function SelectItem({ className, children, size, icon, tooltip, isGroup, ...props }: SelectItemProps): React.JSX.Element;
|
|
11
|
+
declare function SelectSeparator({ className, ...props }: ComponentProps<typeof SelectPrimitive.Separator>): React.JSX.Element;
|
|
12
|
+
declare function SelectScrollUpButton({ className, ...props }: ComponentProps<typeof SelectPrimitive.ScrollUpButton>): React.JSX.Element;
|
|
13
|
+
declare function SelectScrollDownButton({ className, ...props }: ComponentProps<typeof SelectPrimitive.ScrollDownButton>): React.JSX.Element;
|
|
14
|
+
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
import _objectDestructuringEmpty from "@babel/runtime/helpers/objectDestructuringEmpty";
|
|
4
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
5
|
+
var _excluded = ["className", "size", "children", "readOnly", "icon"],
|
|
6
|
+
_excluded2 = ["className", "children", "position"],
|
|
7
|
+
_excluded3 = ["className", "size"],
|
|
8
|
+
_excluded4 = ["className", "children", "size", "icon", "tooltip", "isGroup"],
|
|
9
|
+
_excluded5 = ["className"],
|
|
10
|
+
_excluded6 = ["className"],
|
|
11
|
+
_excluded7 = ["className"];
|
|
12
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
13
|
+
import { inputSizeOptions } from '@scaleflex/ui-tw/input/input.constants';
|
|
14
|
+
import { getBaseInputClasses } from '@scaleflex/ui-tw/input/input.utils';
|
|
15
|
+
import { LabelIcon } from '@scaleflex/ui-tw/label/components/label-icon';
|
|
16
|
+
import { SelectIcon } from '@scaleflex/ui-tw/select/components/select-icon';
|
|
17
|
+
import { selectLabelSizeOptions } from '@scaleflex/ui-tw/select/select.constants';
|
|
18
|
+
import { getOptionInGroupPaddingLeft } from '@scaleflex/ui-tw/select/select.utils';
|
|
19
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
20
|
+
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
21
|
+
import { cva } from 'class-variance-authority';
|
|
22
|
+
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
|
|
23
|
+
import React from 'react';
|
|
24
|
+
function Select(_ref) {
|
|
25
|
+
var props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
26
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Root, _extends({
|
|
27
|
+
"data-slot": "select"
|
|
28
|
+
}, props));
|
|
29
|
+
}
|
|
30
|
+
function SelectGroup(_ref2) {
|
|
31
|
+
var props = _extends({}, (_objectDestructuringEmpty(_ref2), _ref2));
|
|
32
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Group, _extends({
|
|
33
|
+
"data-slot": "select-group"
|
|
34
|
+
}, props));
|
|
35
|
+
}
|
|
36
|
+
function SelectValue(_ref3) {
|
|
37
|
+
var props = _extends({}, (_objectDestructuringEmpty(_ref3), _ref3));
|
|
38
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Value, _extends({
|
|
39
|
+
"data-slot": "select-value"
|
|
40
|
+
}, props));
|
|
41
|
+
}
|
|
42
|
+
var selectTriggerVariants = cva('', {
|
|
43
|
+
variants: {
|
|
44
|
+
size: inputSizeOptions
|
|
45
|
+
},
|
|
46
|
+
defaultVariants: {
|
|
47
|
+
size: FormSize.Md
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
var selectLabelVariants = cva('', {
|
|
51
|
+
variants: {
|
|
52
|
+
size: selectLabelSizeOptions
|
|
53
|
+
},
|
|
54
|
+
defaultVariants: {
|
|
55
|
+
size: FormSize.Md
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
function SelectTrigger(_ref4) {
|
|
59
|
+
var className = _ref4.className,
|
|
60
|
+
_ref4$size = _ref4.size,
|
|
61
|
+
size = _ref4$size === void 0 ? FormSize.Md : _ref4$size,
|
|
62
|
+
children = _ref4.children,
|
|
63
|
+
_ref4$readOnly = _ref4.readOnly,
|
|
64
|
+
readOnly = _ref4$readOnly === void 0 ? false : _ref4$readOnly,
|
|
65
|
+
icon = _ref4.icon,
|
|
66
|
+
props = _objectWithoutProperties(_ref4, _excluded);
|
|
67
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Trigger, _extends({
|
|
68
|
+
"data-slot": "select-trigger",
|
|
69
|
+
"data-size": size,
|
|
70
|
+
className: cn.apply(void 0, ['flex w-full cursor-pointer items-center justify-between gap-2 px-3 py-2 text-sm whitespace-nowrap'].concat(_toConsumableArray(getBaseInputClasses()), ['data-[placeholder]:text-muted-foreground/80 hover:border-secondary-foreground/50', "[&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", selectTriggerVariants({
|
|
71
|
+
size: size,
|
|
72
|
+
className: className
|
|
73
|
+
}), readOnly && 'bg-secondary text-foreground pointer-events-none cursor-default disabled:opacity-100', className]))
|
|
74
|
+
}, props), /*#__PURE__*/React.createElement("div", {
|
|
75
|
+
className: "flex items-center"
|
|
76
|
+
}, icon && /*#__PURE__*/React.createElement(SelectIcon, {
|
|
77
|
+
size: size,
|
|
78
|
+
icon: icon
|
|
79
|
+
}), children), /*#__PURE__*/React.createElement(SelectPrimitive.Icon, {
|
|
80
|
+
asChild: true
|
|
81
|
+
}, /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
82
|
+
className: cn('opacity-50', size === FormSize.Lg ? 'size-5' : 'size-4.5')
|
|
83
|
+
})));
|
|
84
|
+
}
|
|
85
|
+
function SelectContent(_ref5) {
|
|
86
|
+
var className = _ref5.className,
|
|
87
|
+
children = _ref5.children,
|
|
88
|
+
_ref5$position = _ref5.position,
|
|
89
|
+
position = _ref5$position === void 0 ? 'popper' : _ref5$position,
|
|
90
|
+
props = _objectWithoutProperties(_ref5, _excluded2);
|
|
91
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Portal, null, /*#__PURE__*/React.createElement(SelectPrimitive.Content, _extends({
|
|
92
|
+
"data-slot": "select-content",
|
|
93
|
+
className: cn('bg-popover text-popover-foreground relative z-50 max-h-(--max-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md shadow-md', 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', 'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95', position === 'popper' && 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1', className),
|
|
94
|
+
position: position
|
|
95
|
+
}, props), /*#__PURE__*/React.createElement(SelectScrollUpButton, null), /*#__PURE__*/React.createElement(SelectPrimitive.Viewport, {
|
|
96
|
+
className: cn(position === 'popper' && 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1')
|
|
97
|
+
}, children), /*#__PURE__*/React.createElement(SelectScrollDownButton, null)));
|
|
98
|
+
}
|
|
99
|
+
function SelectLabel(_ref6) {
|
|
100
|
+
var className = _ref6.className,
|
|
101
|
+
size = _ref6.size,
|
|
102
|
+
props = _objectWithoutProperties(_ref6, _excluded3);
|
|
103
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Label, _extends({
|
|
104
|
+
"data-slot": "select-label",
|
|
105
|
+
className: cn('text-secondary-foreground font-medium', selectLabelVariants({
|
|
106
|
+
size: size
|
|
107
|
+
}), className)
|
|
108
|
+
}, props));
|
|
109
|
+
}
|
|
110
|
+
function SelectItem(_ref7) {
|
|
111
|
+
var className = _ref7.className,
|
|
112
|
+
children = _ref7.children,
|
|
113
|
+
size = _ref7.size,
|
|
114
|
+
icon = _ref7.icon,
|
|
115
|
+
tooltip = _ref7.tooltip,
|
|
116
|
+
isGroup = _ref7.isGroup,
|
|
117
|
+
props = _objectWithoutProperties(_ref7, _excluded4);
|
|
118
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Item, _extends({
|
|
119
|
+
"data-slot": "select-item",
|
|
120
|
+
className: cn('relative flex w-full cursor-pointer items-center gap-2 text-sm outline-hidden select-none', 'focus:bg-accent focus:text-accent-foreground', '*:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2', 'data-[disabled]:pointer-events-none data-[disabled]:opacity-50', 'data-[state=checked]:bg-accent data-[state=checked]:text-accent-foreground', "[&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", selectTriggerVariants({
|
|
121
|
+
size: size
|
|
122
|
+
}), isGroup && getOptionInGroupPaddingLeft(size), className)
|
|
123
|
+
}, props), /*#__PURE__*/React.createElement("span", {
|
|
124
|
+
className: "absolute right-2 flex size-3.5 items-center justify-center"
|
|
125
|
+
}, /*#__PURE__*/React.createElement(SelectPrimitive.ItemIndicator, null, /*#__PURE__*/React.createElement(CheckIcon, {
|
|
126
|
+
className: cn('text-primary', size === FormSize.Lg ? 'size-5' : 'size-4.5')
|
|
127
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
128
|
+
className: "flex items-center"
|
|
129
|
+
}, icon && /*#__PURE__*/React.createElement(SelectIcon, {
|
|
130
|
+
size: size,
|
|
131
|
+
icon: icon
|
|
132
|
+
}), /*#__PURE__*/React.createElement(SelectPrimitive.ItemText, null, children), tooltip && /*#__PURE__*/React.createElement(LabelIcon, {
|
|
133
|
+
size: size,
|
|
134
|
+
tooltip: tooltip
|
|
135
|
+
})));
|
|
136
|
+
}
|
|
137
|
+
function SelectSeparator(_ref8) {
|
|
138
|
+
var className = _ref8.className,
|
|
139
|
+
props = _objectWithoutProperties(_ref8, _excluded5);
|
|
140
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.Separator, _extends({
|
|
141
|
+
"data-slot": "select-separator",
|
|
142
|
+
className: cn('bg-border pointer-events-none -mx-1 my-1 h-px', className)
|
|
143
|
+
}, props));
|
|
144
|
+
}
|
|
145
|
+
function SelectScrollUpButton(_ref9) {
|
|
146
|
+
var className = _ref9.className,
|
|
147
|
+
props = _objectWithoutProperties(_ref9, _excluded6);
|
|
148
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.ScrollUpButton, _extends({
|
|
149
|
+
"data-slot": "select-scroll-up-button",
|
|
150
|
+
className: cn('flex cursor-default items-center justify-center py-1', className)
|
|
151
|
+
}, props), /*#__PURE__*/React.createElement(ChevronUpIcon, {
|
|
152
|
+
className: "size-4"
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
function SelectScrollDownButton(_ref10) {
|
|
156
|
+
var className = _ref10.className,
|
|
157
|
+
props = _objectWithoutProperties(_ref10, _excluded7);
|
|
158
|
+
return /*#__PURE__*/React.createElement(SelectPrimitive.ScrollDownButton, _extends({
|
|
159
|
+
"data-slot": "select-scroll-down-button",
|
|
160
|
+
className: cn('flex cursor-default items-center justify-center py-1', className)
|
|
161
|
+
}, props), /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
162
|
+
className: "size-4"
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
3
|
+
export var selectLabelSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'py-2 px-3 h-8 text-sm'), FormSize.Md, 'py-3 px-4 h-10 text-base '), FormSize.Lg, 'py-3 px-4 h-12 text-lg ');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
2
|
+
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
3
|
+
import { ComponentProps, ReactElement } from 'react';
|
|
4
|
+
export interface SelectProps extends ComponentProps<typeof SelectPrimitive.Root> {
|
|
5
|
+
}
|
|
6
|
+
export interface SelectTriggerProps extends ComponentProps<typeof SelectPrimitive.Trigger> {
|
|
7
|
+
size?: FormSizeType;
|
|
8
|
+
icon?: ReactElement;
|
|
9
|
+
readOnly?: boolean;
|
|
10
|
+
'aria-invalid'?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface SelectItemProps extends ComponentProps<typeof SelectPrimitive.Item> {
|
|
13
|
+
icon?: ReactElement;
|
|
14
|
+
size?: FormSizeType;
|
|
15
|
+
tooltip?: ReactElement | string;
|
|
16
|
+
isGroup?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface SelectLabelProps extends ComponentProps<typeof SelectPrimitive.Label> {
|
|
19
|
+
size?: FormSizeType;
|
|
20
|
+
}
|
|
21
|
+
export interface SelectIconProps extends ComponentProps<'span'>, Pick<SelectTriggerProps, 'size' | 'icon'> {
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
2
|
+
export var getIconMarginRightInRem = function getIconMarginRightInRem(sizeName) {
|
|
3
|
+
switch (sizeName) {
|
|
4
|
+
case FormSize.Lg:
|
|
5
|
+
return '0.75rem';
|
|
6
|
+
// 12px
|
|
7
|
+
case FormSize.Md:
|
|
8
|
+
return '0.625rem';
|
|
9
|
+
// 10px
|
|
10
|
+
case FormSize.Sm:
|
|
11
|
+
return '0.625rem';
|
|
12
|
+
// 10px
|
|
13
|
+
default:
|
|
14
|
+
return '0.625rem';
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export var getOptionInGroupPaddingLeft = function getOptionInGroupPaddingLeft(sizeName) {
|
|
18
|
+
switch (sizeName) {
|
|
19
|
+
case FormSize.Lg:
|
|
20
|
+
return 'pl-8';
|
|
21
|
+
case FormSize.Md:
|
|
22
|
+
return 'pl-8';
|
|
23
|
+
case FormSize.Sm:
|
|
24
|
+
return 'pl-6';
|
|
25
|
+
default:
|
|
26
|
+
return 'pl-8';
|
|
27
|
+
}
|
|
28
|
+
};
|
package/styles/variables.css
CHANGED
|
@@ -41,7 +41,7 @@ var tooltipVariants = cva('', {
|
|
|
41
41
|
function TooltipContent(_ref4) {
|
|
42
42
|
var className = _ref4.className,
|
|
43
43
|
_ref4$sideOffset = _ref4.sideOffset,
|
|
44
|
-
sideOffset = _ref4$sideOffset === void 0 ?
|
|
44
|
+
sideOffset = _ref4$sideOffset === void 0 ? 6 : _ref4$sideOffset,
|
|
45
45
|
children = _ref4.children,
|
|
46
46
|
_ref4$variant = _ref4.variant,
|
|
47
47
|
variant = _ref4$variant === void 0 ? TooltipVariant.Default : _ref4$variant,
|
|
@@ -49,14 +49,10 @@ function TooltipContent(_ref4) {
|
|
|
49
49
|
return /*#__PURE__*/React.createElement(TooltipPrimitive.Portal, null, /*#__PURE__*/React.createElement(TooltipPrimitive.Content, _extends({
|
|
50
50
|
"data-slot": "tooltip-content",
|
|
51
51
|
sideOffset: sideOffset,
|
|
52
|
-
className: cn('animate-in fade-in-0 zoom-in-95 text-md z-50 w-fit max-w-lg origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-2', 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95', tooltipVariants({
|
|
52
|
+
className: cn('animate-in fade-in-0 zoom-in-95 text-md shadow-shadow z-50 w-fit max-w-lg origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-2 shadow-sm', 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95', tooltipVariants({
|
|
53
53
|
variant: variant
|
|
54
54
|
}), className)
|
|
55
|
-
}, props), children
|
|
56
|
-
className: cn('z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] fill-transparent', tooltipVariants({
|
|
57
|
-
variant: variant
|
|
58
|
-
}))
|
|
59
|
-
})));
|
|
55
|
+
}, props), children));
|
|
60
56
|
}
|
|
61
57
|
function WithTooltip(_ref5) {
|
|
62
58
|
var variant = _ref5.variant,
|