@mbao01/common 0.0.7 → 0.0.8

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 (144) hide show
  1. package/dist/types/components/Avatar/types.d.ts +1 -0
  2. package/dist/types/components/Badge/types.d.ts +1 -0
  3. package/dist/types/components/Breadcrumbs/types.d.ts +1 -0
  4. package/dist/types/components/Combobox/Combobox.d.ts +2 -0
  5. package/dist/types/components/Combobox/index.d.ts +1 -0
  6. package/dist/types/components/Combobox/types.d.ts +19 -0
  7. package/dist/types/components/Command/Command.d.ts +67 -0
  8. package/dist/types/components/Command/constants.d.ts +11 -0
  9. package/dist/types/components/Command/index.d.ts +1 -0
  10. package/dist/types/components/Command/types.d.ts +8 -0
  11. package/dist/types/components/Description/types.d.ts +1 -0
  12. package/dist/types/components/Dialog/Dialog.d.ts +22 -0
  13. package/dist/types/components/Dialog/constants.d.ts +7 -0
  14. package/dist/types/components/Dialog/index.d.ts +1 -0
  15. package/dist/types/components/Dialog/types.d.ts +11 -0
  16. package/dist/types/components/Form/Checkbox/Checkbox.d.ts +6 -0
  17. package/dist/types/components/Form/Checkbox/constants.d.ts +4 -0
  18. package/dist/types/components/Form/Checkbox/index.d.ts +1 -0
  19. package/dist/types/components/Form/Checkbox/types.d.ts +4 -0
  20. package/dist/types/components/Form/Input/Input.d.ts +7 -0
  21. package/dist/types/components/Form/Input/constants.d.ts +6 -0
  22. package/dist/types/components/Form/Input/index.d.ts +1 -0
  23. package/dist/types/components/Form/Input/types.d.ts +4 -0
  24. package/dist/types/components/Form/Phone/Phone.d.ts +17 -0
  25. package/dist/types/components/Form/Phone/constants.d.ts +2 -0
  26. package/dist/types/components/Form/Phone/index.d.ts +1 -0
  27. package/dist/types/components/Form/Phone/types.d.ts +8 -0
  28. package/dist/types/components/Form/Radio/Radio.d.ts +6 -0
  29. package/dist/types/components/Form/Radio/constants.d.ts +4 -0
  30. package/dist/types/components/Form/Radio/index.d.ts +1 -0
  31. package/dist/types/components/Form/Radio/types.d.ts +4 -0
  32. package/dist/types/components/Form/Range/Range.d.ts +8 -0
  33. package/dist/types/components/Form/Range/constants.d.ts +6 -0
  34. package/dist/types/components/Form/Range/index.d.ts +1 -0
  35. package/dist/types/components/Form/Range/types.d.ts +4 -0
  36. package/dist/types/components/Form/Select/Select.d.ts +27 -0
  37. package/dist/types/components/Form/Select/constants.d.ts +17 -0
  38. package/dist/types/components/Form/Select/index.d.ts +1 -0
  39. package/dist/types/components/Form/Select/types.d.ts +7 -0
  40. package/dist/types/components/Form/Slider/Slider.d.ts +15 -0
  41. package/dist/types/components/Form/Slider/constants.d.ts +15 -0
  42. package/dist/types/components/Form/Slider/index.d.ts +1 -0
  43. package/dist/types/components/Form/Slider/types.d.ts +5 -0
  44. package/dist/types/components/Form/Switch/Switch.d.ts +6 -0
  45. package/dist/types/components/Form/Switch/constants.d.ts +4 -0
  46. package/dist/types/components/Form/Switch/index.d.ts +1 -0
  47. package/dist/types/components/Form/Switch/types.d.ts +4 -0
  48. package/dist/types/components/Form/TextField/TextField.d.ts +10 -0
  49. package/dist/types/components/Form/TextField/constants.d.ts +1 -0
  50. package/dist/types/components/Form/TextField/index.d.ts +1 -0
  51. package/dist/types/components/Form/TextField/types.d.ts +6 -0
  52. package/dist/types/components/Form/Textarea/Textarea.d.ts +8 -0
  53. package/dist/types/components/Form/Textarea/constants.d.ts +6 -0
  54. package/dist/types/components/Form/Textarea/index.d.ts +1 -0
  55. package/dist/types/components/Form/Textarea/types.d.ts +4 -0
  56. package/dist/types/components/Form/components/FormControl/FormControl.d.ts +2 -0
  57. package/dist/types/components/Form/components/FormControl/constants.d.ts +1 -0
  58. package/dist/types/components/Form/components/FormControl/index.d.ts +1 -0
  59. package/dist/types/components/Form/components/FormControl/types.d.ts +9 -0
  60. package/dist/types/components/Form/components/Label/Label.d.ts +7 -0
  61. package/dist/types/components/Form/components/Label/constants.d.ts +1 -0
  62. package/dist/types/components/Form/components/Label/index.d.ts +1 -0
  63. package/dist/types/components/Form/components/Label/types.d.ts +6 -0
  64. package/dist/types/components/Form/index.d.ts +11 -0
  65. package/dist/types/components/Loading/types.d.ts +1 -0
  66. package/dist/types/components/Popover/Popover.d.ts +9 -0
  67. package/dist/types/components/Popover/constants.d.ts +1 -0
  68. package/dist/types/components/Popover/index.d.ts +1 -0
  69. package/dist/types/components/Popover/types.d.ts +6 -0
  70. package/dist/types/components/Progress/types.d.ts +1 -0
  71. package/dist/types/components/Separator/types.d.ts +1 -0
  72. package/dist/types/components/Skeleton/types.d.ts +1 -0
  73. package/dist/types/components/Text/Text.d.ts +2 -2
  74. package/dist/types/components/Text/types.d.ts +6 -2
  75. package/dist/types/components/Tooltip/types.d.ts +1 -0
  76. package/dist/types/index.d.ts +6 -0
  77. package/package.json +21 -13
  78. package/src/components/Combobox/Combobox.tsx +82 -0
  79. package/src/components/Combobox/index.ts +1 -0
  80. package/src/components/Combobox/types.ts +21 -0
  81. package/src/components/Command/Command.tsx +142 -0
  82. package/src/components/Command/constants.ts +39 -0
  83. package/src/components/Command/index.ts +1 -0
  84. package/src/components/Command/types.ts +16 -0
  85. package/src/components/Dialog/Dialog.tsx +105 -0
  86. package/src/components/Dialog/constants.ts +27 -0
  87. package/src/components/Dialog/index.ts +1 -0
  88. package/src/components/Dialog/types.ts +40 -0
  89. package/src/components/Form/Checkbox/Checkbox.tsx +18 -0
  90. package/src/components/Form/Checkbox/constants.ts +21 -0
  91. package/src/components/Form/Checkbox/index.ts +1 -0
  92. package/src/components/Form/Checkbox/types.ts +8 -0
  93. package/src/components/Form/Input/Input.tsx +18 -0
  94. package/src/components/Form/Input/constants.ts +37 -0
  95. package/src/components/Form/Input/index.ts +1 -0
  96. package/src/components/Form/Input/types.ts +8 -0
  97. package/src/components/Form/Phone/Phone.tsx +120 -0
  98. package/src/components/Form/Phone/constants.ts +7 -0
  99. package/src/components/Form/Phone/index.ts +1 -0
  100. package/src/components/Form/Phone/types.ts +12 -0
  101. package/src/components/Form/Radio/Radio.tsx +18 -0
  102. package/src/components/Form/Radio/constants.ts +21 -0
  103. package/src/components/Form/Radio/index.ts +1 -0
  104. package/src/components/Form/Radio/types.ts +8 -0
  105. package/src/components/Form/Range/Range.tsx +22 -0
  106. package/src/components/Form/Range/constants.ts +31 -0
  107. package/src/components/Form/Range/index.ts +1 -0
  108. package/src/components/Form/Range/types.ts +8 -0
  109. package/src/components/Form/Select/Select.tsx +151 -0
  110. package/src/components/Form/Select/constants.ts +80 -0
  111. package/src/components/Form/Select/index.ts +1 -0
  112. package/src/components/Form/Select/types.ts +18 -0
  113. package/src/components/Form/Slider/Slider.tsx +43 -0
  114. package/src/components/Form/Slider/constants.ts +87 -0
  115. package/src/components/Form/Slider/index.ts +1 -0
  116. package/src/components/Form/Slider/types.ts +16 -0
  117. package/src/components/Form/Switch/Switch.tsx +19 -0
  118. package/src/components/Form/Switch/constants.ts +21 -0
  119. package/src/components/Form/Switch/index.ts +1 -0
  120. package/src/components/Form/Switch/types.ts +8 -0
  121. package/src/components/Form/TextField/TextField.tsx +37 -0
  122. package/src/components/Form/TextField/constants.ts +5 -0
  123. package/src/components/Form/TextField/index.ts +1 -0
  124. package/src/components/Form/TextField/types.ts +7 -0
  125. package/src/components/Form/Textarea/Textarea.tsx +22 -0
  126. package/src/components/Form/Textarea/constants.ts +37 -0
  127. package/src/components/Form/Textarea/index.ts +1 -0
  128. package/src/components/Form/Textarea/types.ts +8 -0
  129. package/src/components/Form/components/FormControl/FormControl.tsx +21 -0
  130. package/src/components/Form/components/FormControl/constants.ts +3 -0
  131. package/src/components/Form/components/FormControl/index.ts +1 -0
  132. package/src/components/Form/components/FormControl/types.ts +13 -0
  133. package/src/components/Form/components/Label/Label.tsx +22 -0
  134. package/src/components/Form/components/Label/constants.ts +3 -0
  135. package/src/components/Form/components/Label/index.ts +1 -0
  136. package/src/components/Form/components/Label/types.ts +10 -0
  137. package/src/components/Form/index.ts +11 -0
  138. package/src/components/Popover/Popover.tsx +30 -0
  139. package/src/components/Popover/constants.ts +5 -0
  140. package/src/components/Popover/index.ts +1 -0
  141. package/src/components/Popover/types.ts +12 -0
  142. package/src/components/Text/Text.tsx +3 -3
  143. package/src/components/Text/types.ts +8 -5
  144. package/src/index.ts +7 -0
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ import { type CheckboxProps } from "./types";
3
+ import { getCheckboxClasses } from "./constants";
4
+ import { cn } from "../../../utilities";
5
+
6
+ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
7
+ ({ className, size, variant, ...props }, ref) => (
8
+ <input
9
+ ref={ref}
10
+ type="checkbox"
11
+ className={cn(getCheckboxClasses({ size, variant }), className)}
12
+ {...props}
13
+ />
14
+ )
15
+ );
16
+ Checkbox.displayName = "Checkbox";
17
+
18
+ export { Checkbox };
@@ -0,0 +1,21 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getCheckboxClasses = cva("checkbox", {
4
+ variants: {
5
+ variant: {
6
+ primary: "checkbox-primary",
7
+ secondary: "checkbox-secondary",
8
+ accent: "checkbox-accent",
9
+ success: "checkbox-success",
10
+ warning: "checkbox-warning",
11
+ info: "checkbox-info",
12
+ error: "checkbox-error",
13
+ },
14
+ size: {
15
+ xs: "checkbox-xs",
16
+ sm: "checkbox-sm",
17
+ md: "checkbox-md",
18
+ lg: "checkbox-lg",
19
+ },
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export { Checkbox } from "./Checkbox";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getCheckboxClasses } from "./constants";
3
+
4
+ export type CheckboxProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref" | "type"
7
+ > &
8
+ VariantProps<typeof getCheckboxClasses>;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { type InputProps } from "./types";
3
+ import { cn } from "../../../utilities";
4
+ import { getInputClasses } from "./constants";
5
+
6
+ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
7
+ ({ size, variant, wide, outline, className, ...props }: InputProps, ref) => (
8
+ <input
9
+ ref={ref}
10
+ className={cn(
11
+ getInputClasses({ size, wide, variant, outline }),
12
+ className
13
+ )}
14
+ {...props}
15
+ />
16
+ )
17
+ );
18
+ Input.displayName = "Input";
@@ -0,0 +1,37 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getInputClasses = cva(
4
+ "input rounded-md transition-all duration-100",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ accent: "input-accent",
9
+ error: "input-error",
10
+ ghost: "input-ghost",
11
+ info: "input-info",
12
+ primary: "input-primary",
13
+ secondary: "input-secondary",
14
+ success: "input-success",
15
+ warning: "input-warning",
16
+ },
17
+ outline: {
18
+ true: "input-bordered",
19
+ },
20
+ wide: {
21
+ true: "w-full",
22
+ },
23
+ size: {
24
+ xs: "input-xs",
25
+ sm: "input-sm",
26
+ md: "input-md",
27
+ lg: "input-lg",
28
+ },
29
+ },
30
+ compoundVariants: [
31
+ {
32
+ size: undefined,
33
+ className: "min-h-fit h-10",
34
+ },
35
+ ],
36
+ }
37
+ );
@@ -0,0 +1 @@
1
+ export { Input } from "./Input";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getInputClasses } from "./constants";
3
+
4
+ export type InputProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref"
7
+ > &
8
+ VariantProps<typeof getInputClasses>;
@@ -0,0 +1,120 @@
1
+ "use client";
2
+
3
+ import React, { MutableRefObject } from "react";
4
+ import {
5
+ defaultCountries,
6
+ usePhoneInput,
7
+ FlagImage,
8
+ } from "react-international-phone";
9
+ import { type PhoneProps } from "./types";
10
+ import { Popover } from "../../Popover";
11
+ import { Command } from "../../Command";
12
+ import { cn } from "../../../utilities";
13
+ import { Button } from "../../Button";
14
+ import { Input } from "../Input";
15
+ import { getPhoneButtonClasses, getPhoneInputClasses } from "./constants";
16
+ import { getInputClasses } from "../Input/constants";
17
+ import { getButtonClasses } from "../../Button/constants";
18
+
19
+ const Phone = React.forwardRef<HTMLInputElement, PhoneProps>(
20
+ (
21
+ {
22
+ defaultValue,
23
+ className,
24
+ placeholder,
25
+ onChange,
26
+ inputProps,
27
+ buttonProps,
28
+ ...props
29
+ },
30
+ ref
31
+ ) => {
32
+ const [open, setOpen] = React.useState(false);
33
+ const {
34
+ inputValue,
35
+ handlePhoneValueChange,
36
+ inputRef,
37
+ country,
38
+ setCountry,
39
+ } = usePhoneInput({
40
+ value: String(defaultValue) ?? "+231",
41
+ defaultCountry: "lr",
42
+ forceDialCode: true,
43
+ inputRef: ref as MutableRefObject<HTMLInputElement | null>,
44
+ });
45
+
46
+ const options = defaultCountries.map((country) => ({
47
+ label: country[0],
48
+ value: country[1],
49
+ }));
50
+
51
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
52
+ handlePhoneValueChange(e);
53
+ onChange?.(e);
54
+ };
55
+
56
+ return (
57
+ <div className="join">
58
+ <Popover open={open} onOpenChange={setOpen}>
59
+ <Popover.Trigger asChild>
60
+ <Button
61
+ role="combobox"
62
+ aria-expanded={open}
63
+ className={cn(
64
+ getPhoneButtonClasses(),
65
+ getButtonClasses(buttonProps)
66
+ )}
67
+ >
68
+ <FlagImage iso2={country.iso2} size="30px" />
69
+ </Button>
70
+ </Popover.Trigger>
71
+ <Popover.Content className="w-[200px] p-0">
72
+ <Command>
73
+ <Command.Input placeholder="Search country..." />
74
+ <Command.Empty>No country found.</Command.Empty>
75
+ <Command.List>
76
+ <Command.Group>
77
+ {options.map((option) => (
78
+ <Command.Item
79
+ key={option.value}
80
+ value={option.value}
81
+ keywords={[option.label, option.value]}
82
+ onSelect={(currentValue) => {
83
+ setCountry(currentValue);
84
+ setOpen(false);
85
+ }}
86
+ className={cn({
87
+ "bg-base-300": country.iso2 === option.value,
88
+ })}
89
+ >
90
+ <FlagImage iso2={option.value} size="20px" />
91
+ <span className="truncate ml-2">{option.label}</span>
92
+ </Command.Item>
93
+ ))}
94
+ </Command.Group>
95
+ </Command.List>
96
+ </Command>
97
+ </Popover.Content>
98
+ </Popover>
99
+ <Input
100
+ type="text"
101
+ ref={inputRef}
102
+ value={inputValue}
103
+ pattern="^\+\d{1,4}\s\d{6,}$"
104
+ inputMode="numeric"
105
+ placeholder={placeholder ?? " "}
106
+ onChange={handleInputChange}
107
+ className={cn(
108
+ getPhoneInputClasses(),
109
+ getInputClasses(inputProps),
110
+ className
111
+ )}
112
+ {...props}
113
+ />
114
+ </div>
115
+ );
116
+ }
117
+ );
118
+ Phone.displayName = "Phone";
119
+
120
+ export { Phone };
@@ -0,0 +1,7 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getPhoneButtonClasses = cva("join-item justify-between px-2");
4
+
5
+ export const getPhoneInputClasses = cva(
6
+ "input join-item input-bordered h-10 w-full rounded-md !rounded-r-md !pl-2 text-sm transition-all duration-100"
7
+ );
@@ -0,0 +1 @@
1
+ export { Phone } from "./Phone";
@@ -0,0 +1,12 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { type InputProps } from "../Input/types";
3
+ import { getInputClasses } from "../Input/constants";
4
+ import { getButtonClasses } from "../../Button/constants";
5
+
6
+ export type PhoneProps = Omit<
7
+ InputProps,
8
+ "type" | "size" | "label" | "inputMode"
9
+ > & {
10
+ inputProps?: VariantProps<typeof getInputClasses>;
11
+ buttonProps?: VariantProps<typeof getButtonClasses>;
12
+ };
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ import { type RadioProps } from "./types";
3
+ import { getRadioClasses } from "./constants";
4
+ import { cn } from "../../../utilities";
5
+
6
+ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
7
+ ({ className, size, variant, ...props }, ref) => (
8
+ <input
9
+ ref={ref}
10
+ type="radio"
11
+ className={cn(getRadioClasses({ size, variant }), className)}
12
+ {...props}
13
+ />
14
+ )
15
+ );
16
+ Radio.displayName = "Radio";
17
+
18
+ export { Radio };
@@ -0,0 +1,21 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getRadioClasses = cva("radio", {
4
+ variants: {
5
+ variant: {
6
+ primary: "radio-primary",
7
+ secondary: "radio-secondary",
8
+ accent: "radio-accent",
9
+ success: "radio-success",
10
+ warning: "radio-warning",
11
+ info: "radio-info",
12
+ error: "radio-error",
13
+ },
14
+ size: {
15
+ xs: "radio-xs",
16
+ sm: "radio-sm",
17
+ md: "radio-md",
18
+ lg: "radio-lg",
19
+ },
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export { Radio } from "./Radio";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getRadioClasses } from "./constants";
3
+
4
+ export type RadioProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref" | "type"
7
+ > &
8
+ VariantProps<typeof getRadioClasses>;
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ import { type RangeProps } from "./types";
3
+ import { getRangeClasses } from "./constants";
4
+ import { cn } from "../../../utilities";
5
+
6
+ const Range = React.forwardRef<HTMLInputElement, RangeProps>(
7
+ ({ className, size, variant, wide, disabled, ...props }, ref) => (
8
+ <input
9
+ ref={ref}
10
+ type="range"
11
+ disabled={disabled}
12
+ className={cn(
13
+ getRangeClasses({ size, variant, wide, disabled }),
14
+ className
15
+ )}
16
+ {...props}
17
+ />
18
+ )
19
+ );
20
+ Range.displayName = "Range";
21
+
22
+ export { Range };
@@ -0,0 +1,31 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getRangeClasses = cva("range", {
4
+ variants: {
5
+ variant: {
6
+ primary: "range-primary",
7
+ secondary: "range-secondary",
8
+ accent: "range-accent",
9
+ success: "range-success",
10
+ warning: "range-warning",
11
+ info: "range-info",
12
+ error: "range-error",
13
+ neutral: "range-neutral",
14
+ },
15
+ disabled: {
16
+ true: "cursor-not-allowed opacity-80",
17
+ },
18
+ wide: {
19
+ true: "w-full",
20
+ },
21
+ size: {
22
+ xs: "range-xs",
23
+ sm: "range-sm",
24
+ md: "range-md",
25
+ lg: "range-lg",
26
+ },
27
+ },
28
+ defaultVariants: {
29
+ variant: "neutral",
30
+ },
31
+ });
@@ -0,0 +1 @@
1
+ export { Range } from "./Range";
@@ -0,0 +1,8 @@
1
+ import { type VariantProps } from "../../../libs";
2
+ import { getRangeClasses } from "./constants";
3
+
4
+ export type RangeProps = Omit<
5
+ React.HTMLProps<HTMLInputElement>,
6
+ "size" | "ref" | "type"
7
+ > &
8
+ VariantProps<typeof getRangeClasses>;
@@ -0,0 +1,151 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ CheckIcon,
6
+ ChevronDownIcon,
7
+ ChevronUpIcon,
8
+ } from "@radix-ui/react-icons";
9
+ import * as SelectPrimitive from "@radix-ui/react-select";
10
+ import type {
11
+ SelectContentProps,
12
+ SelectItemProps,
13
+ SelectTriggerProps,
14
+ } from "./types";
15
+ import { cn } from "../../../utilities";
16
+ import {
17
+ getSelectContentClasses,
18
+ getSelectItemClasses,
19
+ getSelectLabelClasses,
20
+ getSelectSeparatorClasses,
21
+ getSelectTriggerClasses,
22
+ getSelectViewportClasses,
23
+ } from "./constants";
24
+
25
+ const Select = (
26
+ props: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Root>
27
+ ) => <SelectPrimitive.Root {...props} />;
28
+
29
+ const SelectTrigger = React.forwardRef<
30
+ React.ElementRef<typeof SelectPrimitive.Trigger>,
31
+ SelectTriggerProps
32
+ >(({ className, children, size, wide, variant, outline, ...props }, ref) => (
33
+ <SelectPrimitive.Trigger
34
+ ref={ref}
35
+ className={cn(
36
+ getSelectTriggerClasses({ size, wide, variant, outline }),
37
+ className
38
+ )}
39
+ {...props}
40
+ >
41
+ {children}
42
+ </SelectPrimitive.Trigger>
43
+ ));
44
+ SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
45
+
46
+ const SelectScrollUpButton = React.forwardRef<
47
+ React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
48
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
49
+ >((props, ref) => (
50
+ <SelectPrimitive.ScrollUpButton
51
+ ref={ref}
52
+ className={cn("flex cursor-default items-center justify-center py-1")}
53
+ {...props}
54
+ >
55
+ <ChevronUpIcon />
56
+ </SelectPrimitive.ScrollUpButton>
57
+ ));
58
+ SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
59
+
60
+ const SelectScrollDownButton = React.forwardRef<
61
+ React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
62
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
63
+ >((props, ref) => (
64
+ <SelectPrimitive.ScrollDownButton
65
+ ref={ref}
66
+ className={cn("flex cursor-default items-center justify-center py-1")}
67
+ {...props}
68
+ >
69
+ <ChevronDownIcon />
70
+ </SelectPrimitive.ScrollDownButton>
71
+ ));
72
+ SelectScrollDownButton.displayName =
73
+ SelectPrimitive.ScrollDownButton.displayName;
74
+
75
+ const SelectContent = React.forwardRef<
76
+ React.ElementRef<typeof SelectPrimitive.Content>,
77
+ SelectContentProps
78
+ >(({ className, children, position = "popper", ...props }, ref) => (
79
+ <SelectPrimitive.Portal>
80
+ <SelectPrimitive.Content
81
+ ref={ref}
82
+ className={cn(getSelectContentClasses({ position }), className)}
83
+ position={position}
84
+ {...props}
85
+ >
86
+ <SelectScrollUpButton />
87
+ <SelectPrimitive.Viewport
88
+ className={cn(getSelectViewportClasses({ position }))}
89
+ >
90
+ {children}
91
+ </SelectPrimitive.Viewport>
92
+ <SelectScrollDownButton />
93
+ </SelectPrimitive.Content>
94
+ </SelectPrimitive.Portal>
95
+ ));
96
+ SelectContent.displayName = SelectPrimitive.Content.displayName;
97
+
98
+ const SelectLabel = React.forwardRef<
99
+ React.ElementRef<typeof SelectPrimitive.Label>,
100
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
101
+ >((props, ref) => (
102
+ <SelectPrimitive.Label
103
+ ref={ref}
104
+ className={cn(getSelectLabelClasses())}
105
+ {...props}
106
+ />
107
+ ));
108
+ SelectLabel.displayName = SelectPrimitive.Label.displayName;
109
+
110
+ const SelectItem = React.forwardRef<
111
+ React.ElementRef<typeof SelectPrimitive.Item>,
112
+ SelectItemProps
113
+ >(({ className, children, variant, ...props }, ref) => (
114
+ <SelectPrimitive.Item
115
+ ref={ref}
116
+ className={cn(getSelectItemClasses({ variant }), className)}
117
+ {...props}
118
+ >
119
+ <span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
120
+ <SelectPrimitive.ItemIndicator>
121
+ <CheckIcon className="h-4 w-4" />
122
+ </SelectPrimitive.ItemIndicator>
123
+ </span>
124
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
125
+ </SelectPrimitive.Item>
126
+ ));
127
+ SelectItem.displayName = SelectPrimitive.Item.displayName;
128
+
129
+ const SelectSeparator = React.forwardRef<
130
+ React.ElementRef<typeof SelectPrimitive.Separator>,
131
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
132
+ >((props, ref) => (
133
+ <SelectPrimitive.Separator
134
+ ref={ref}
135
+ className={cn(getSelectSeparatorClasses())}
136
+ {...props}
137
+ />
138
+ ));
139
+ SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
140
+
141
+ Select.Group = SelectPrimitive.Group;
142
+ Select.Value = SelectPrimitive.Value;
143
+ Select.Trigger = SelectTrigger;
144
+ Select.Content = SelectContent;
145
+ Select.Label = SelectLabel;
146
+ Select.Item = SelectItem;
147
+ Select.Separator = SelectSeparator;
148
+ Select.ScrollUpButton = SelectScrollUpButton;
149
+ Select.ScrollDownButton = SelectScrollDownButton;
150
+
151
+ export { Select };
@@ -0,0 +1,80 @@
1
+ import { cva } from "../../../libs";
2
+
3
+ export const getSelectTriggerClasses = cva(
4
+ "select flex items-center justify-between rounded-md text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
5
+ {
6
+ variants: {
7
+ variant: {
8
+ primary: "select-primary",
9
+ secondary: "select-secondary",
10
+ accent: "select-accent",
11
+ success: "select-success",
12
+ warning: "select-warning",
13
+ info: "select-info",
14
+ error: "select-error",
15
+ },
16
+ outline: {
17
+ true: "select-bordered border border-input",
18
+ },
19
+ wide: {
20
+ true: "w-full",
21
+ },
22
+ size: {
23
+ xs: "select-xs",
24
+ sm: "select-sm",
25
+ md: "select-md",
26
+ lg: "select-lg",
27
+ },
28
+ },
29
+ compoundVariants: [
30
+ {
31
+ size: undefined,
32
+ className: "min-h-fit h-10",
33
+ },
34
+ ],
35
+ }
36
+ );
37
+
38
+ export const getSelectItemClasses = cva(
39
+ "relative flex w-full cursor-pointer select-none items-center focus:bg-neutral focus:text-neutral-content rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
40
+ {
41
+ variants: {
42
+ variant: {
43
+ primary: "focus:bg-primary focus:text-primary-content",
44
+ secondary: "focus:bg-secondary focus:text-secondary-content",
45
+ accent: "focus:bg-accent focus:text-accent-content",
46
+ success: "focus:bg-success focus:text-success-content",
47
+ warning: "focus:bg-warning focus:text-warning-content",
48
+ info: "focus:bg-info focus:text-info-content",
49
+ error: "focus:bg-error focus:text-error-content",
50
+ },
51
+ },
52
+ }
53
+ );
54
+
55
+ export const getSelectLabelClasses = cva("px-2 py-1.5 text-sm font-semibold");
56
+
57
+ export const getSelectSeparatorClasses = cva("-mx-1 my-1 h-px bg-muted");
58
+
59
+ export const getSelectContentClasses = cva(
60
+ "relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 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",
61
+ {
62
+ variants: {
63
+ position: {
64
+ popper:
65
+ "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
66
+ "item-aligned": "",
67
+ },
68
+ },
69
+ }
70
+ );
71
+
72
+ export const getSelectViewportClasses = cva("p-1", {
73
+ variants: {
74
+ position: {
75
+ popper:
76
+ "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]",
77
+ "item-aligned": "",
78
+ },
79
+ },
80
+ });
@@ -0,0 +1 @@
1
+ export { Select } from "./Select";
@@ -0,0 +1,18 @@
1
+ import * as SelectPrimitive from "@radix-ui/react-select";
2
+ import { type VariantProps } from "../../../libs";
3
+ import { getSelectContentClasses, getSelectTriggerClasses } from "./constants";
4
+
5
+ export type SelectTriggerProps = React.ComponentPropsWithoutRef<
6
+ typeof SelectPrimitive.Trigger
7
+ > &
8
+ VariantProps<typeof getSelectTriggerClasses>;
9
+
10
+ export type SelectItemProps = React.ComponentPropsWithoutRef<
11
+ typeof SelectPrimitive.Item
12
+ > &
13
+ VariantProps<typeof getSelectTriggerClasses>;
14
+
15
+ export type SelectContentProps = React.ComponentPropsWithoutRef<
16
+ typeof SelectPrimitive.Content
17
+ > &
18
+ VariantProps<typeof getSelectContentClasses>;