@purr-react-tailwindcss/components.select 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ISelectMenuProps } from '../_types';
3
+
4
+ export declare const SelectMenu: React.ForwardRefExoticComponent<ISelectMenuProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ISelectOptionProps } from '../_types';
3
+
4
+ export declare const SelectOption: React.MemoExoticComponent<({ value, displayedValue, label, disabled, htmlAttributes, handleSelectOption, }: ISelectOptionProps) => React.JSX.Element>;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { ISelectProps } from '../_types';
3
+
4
+ export declare const Select: React.ForwardRefExoticComponent<ISelectProps & React.RefAttributes<HTMLSelectElement>>;
@@ -0,0 +1,72 @@
1
+ import { jsx as c } from "react/jsx-runtime";
2
+ import s from "clsx";
3
+ import { memo as b, forwardRef as h, useMemo as n } from "react";
4
+ const p = b(
5
+ ({
6
+ value: t,
7
+ displayedValue: e,
8
+ label: l,
9
+ disabled: r,
10
+ htmlAttributes: x,
11
+ handleSelectOption: a
12
+ }) => /* @__PURE__ */ c(
13
+ "button",
14
+ {
15
+ className: s(
16
+ "block h-9 w-full cursor-pointer overflow-hidden overflow-ellipsis whitespace-nowrap px-3.5 text-left font-sans text-base transition-all duration-200 ease-in-out hover:bg-white/10",
17
+ r && "bg-gray-900 text-white/50",
18
+ !r && t === e && "bg-sky-400/20 text-white",
19
+ !r && t !== e && "bg-transparent text-white",
20
+ "select-option",
21
+ t === e && "select-option--selected",
22
+ r && "select-option--disabled"
23
+ ),
24
+ onClick: a(t),
25
+ ...x,
26
+ title: typeof l == "string" ? l : void 0,
27
+ children: l
28
+ }
29
+ )
30
+ );
31
+ p.displayName = "SelectOption";
32
+ const o = h(
33
+ ({ options: t, position: e, isShowed: l, currentValue: r, htmlAttributes: x, selectOption: a }, d) => {
34
+ const m = n(() => t.map((f) => /* @__PURE__ */ c(
35
+ p,
36
+ {
37
+ value: f.value,
38
+ displayedValue: r,
39
+ label: f.label,
40
+ disabled: !!f.disabled,
41
+ htmlAttributes: f.htmlAttributes,
42
+ handleSelectOption: a
43
+ },
44
+ f.value
45
+ )), [r, t, a]);
46
+ return /* @__PURE__ */ c(
47
+ "div",
48
+ {
49
+ ref: d,
50
+ className: s(
51
+ "absolute z-50 min-w-32 rounded bg-gray-900 px-0 py-1.5",
52
+ "shadow-[0px_5px_5px_-3px_rgba(0,0,0,0.2),0px_8px_10px_1px_rgba(0,0,0,0.14),0px_3px_14px_2px_rgba(0,0,0,0.12)]",
53
+ "bg-gradient-to-b from-[#ffffff1f] to-[#ffffff1f]",
54
+ l ? "block" : "hidden",
55
+ "select-options",
56
+ l && "select-options--showed"
57
+ ),
58
+ style: {
59
+ top: `${(e == null ? void 0 : e.top) || 0}px`,
60
+ left: `${(e == null ? void 0 : e.left) || 0}px`,
61
+ width: `${(e == null ? void 0 : e.width) || 0}px`
62
+ },
63
+ ...x,
64
+ children: m
65
+ }
66
+ );
67
+ }
68
+ );
69
+ o.displayName = "SelectMenu";
70
+ export {
71
+ o as SelectMenu
72
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),n=require("clsx"),f=require("react"),d=f.memo(({value:t,displayedValue:e,label:l,disabled:r,htmlAttributes:a,handleSelectOption:s})=>x.jsx("button",{className:n("block h-9 w-full cursor-pointer overflow-hidden overflow-ellipsis whitespace-nowrap px-3.5 text-left font-sans text-base transition-all duration-200 ease-in-out hover:bg-white/10",r&&"bg-gray-900 text-white/50",!r&&t===e&&"bg-sky-400/20 text-white",!r&&t!==e&&"bg-transparent text-white","select-option",t===e&&"select-option--selected",r&&"select-option--disabled"),onClick:s(t),...a,title:typeof l=="string"?l:void 0,children:l}));d.displayName="SelectOption";const u=f.forwardRef(({options:t,position:e,isShowed:l,currentValue:r,htmlAttributes:a,selectOption:s},b)=>{const p=f.useMemo(()=>t.map(c=>x.jsx(d,{value:c.value,displayedValue:r,label:c.label,disabled:!!c.disabled,htmlAttributes:c.htmlAttributes,handleSelectOption:s},c.value)),[r,t,s]);return x.jsx("div",{ref:b,className:n("absolute z-50 min-w-32 rounded bg-gray-900 px-0 py-1.5","shadow-[0px_5px_5px_-3px_rgba(0,0,0,0.2),0px_8px_10px_1px_rgba(0,0,0,0.14),0px_3px_14px_2px_rgba(0,0,0,0.12)]","bg-gradient-to-b from-[#ffffff1f] to-[#ffffff1f]",l?"block":"hidden","select-options",l&&"select-options--showed"),style:{top:`${(e==null?void 0:e.top)||0}px`,left:`${(e==null?void 0:e.left)||0}px`,width:`${(e==null?void 0:e.width)||0}px`},...a,children:p})});u.displayName="SelectMenu";exports.SelectMenu=u;
@@ -0,0 +1,51 @@
1
+ import { HTMLAttributes, MouseEvent, MouseEventHandler, ReactNode } from 'react';
2
+ import { FieldError } from 'react-hook-form';
3
+ import { IExtendable } from '@purr-core/utils.definitions';
4
+ import { IHelperTextProps } from '@purr-react-tailwindcss/components.helper-text';
5
+ import { ILabelProps } from '@purr-react-tailwindcss/components.label';
6
+ import { IPostAdornmentProps } from '@purr-react-tailwindcss/components.post-adornment';
7
+
8
+ export interface ISelectOption {
9
+ value: string;
10
+ label: ReactNode;
11
+ disabled?: boolean;
12
+ htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
13
+ }
14
+ export interface ISelectOptionProps extends ISelectOption {
15
+ displayedValue?: string;
16
+ handleSelectOption: (value: string) => MouseEventHandler<HTMLSpanElement>;
17
+ }
18
+ export type TSelectVariant = "standard" | "outlined" | "filled";
19
+ export interface ISelectMenuProps {
20
+ options: ISelectOption[];
21
+ position: {
22
+ left: number;
23
+ top: number;
24
+ width: number;
25
+ height: number;
26
+ } | null;
27
+ isShowed: boolean;
28
+ currentValue?: string;
29
+ htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
30
+ selectOption: (value: string) => MouseEventHandler<HTMLSpanElement>;
31
+ }
32
+ export interface ISelectProps {
33
+ options: ISelectOption[];
34
+ value?: string;
35
+ variant?: TSelectVariant;
36
+ labelProps?: ILabelProps;
37
+ postAdornmentProps?: IPostAdornmentProps;
38
+ helperTextProps?: IHelperTextProps;
39
+ htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
40
+ menuHtmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
41
+ boxHtmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
42
+ fakeSelectHtmlAttributes?: HTMLAttributes<HTMLSelectElement> & IExtendable;
43
+ displayedOptionHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
44
+ tabIndex?: number;
45
+ fullWidth?: boolean;
46
+ disabled?: boolean;
47
+ required?: boolean;
48
+ error?: FieldError;
49
+ isStandalone?: boolean;
50
+ onChange?: (value: string, e: MouseEvent<HTMLSpanElement>) => void;
51
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var O=Object.create;var R=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var U=(t,s,e,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of J(s))!Q.call(t,c)&&c!==e&&R(t,c,{get:()=>s[c],enumerable:!(i=Y(s,c))||i.enumerable});return t};var j=(t,s,e)=>(e=t!=null?O(K(t)):{},U(s||!t||!t.__esModule?R(e,"default",{value:t,enumerable:!0}):e,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),g=require("clsx"),n=require("react"),X=require("@purr-core/components.portal"),Z=require("@purr-core/hooks.block"),b=require("@purr-core/hooks.not-click-on-elements"),W=require("@purr-core/hooks.sync-state-with-props"),z=require("@purr-react-tailwindcss/utils.helpers"),T=n.lazy(()=>import("@purr-react-tailwindcss/components.helper-text").then(t=>({default:t.HelperText}))),A=n.lazy(()=>import("@purr-react-tailwindcss/components.icon").then(t=>({default:t.Icon}))),P=n.lazy(()=>import("@purr-react-tailwindcss/components.label").then(t=>({default:t.Label}))),p=n.lazy(()=>import("@purr-react-tailwindcss/components.post-adornment").then(t=>({default:t.PostAdornment}))),ee=n.lazy(()=>Promise.resolve().then(()=>require("./_menu-CedOsSIk.cjs")).then(t=>({default:t.SelectMenu}))),te=(t,s=!0)=>{var i;const e=(i=t.current)==null?void 0:i.getBoundingClientRect();return{left:(e==null?void 0:e.x)||0,top:((e==null?void 0:e.y)||0)+(s&&(window==null?void 0:window.scrollY)||0),width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0}},L=n.forwardRef(({options:t,value:s,variant:e="standard",labelProps:i,postAdornmentProps:c,helperTextProps:r,fullWidth:d=!1,disabled:u=!1,required:q=!1,error:o=null,isStandalone:k=!1,tabIndex:C=-1,menuHtmlAttributes:M,htmlAttributes:E,boxHtmlAttributes:I,fakeSelectHtmlAttributes:V,displayedOptionHtmlAttributes:_,onChange:w},ce)=>{const N=n.useRef(null),v=n.useRef(null),[a,S]=n.useState(!1),[B,H]=n.useState(null),{currentValue:m,setCurrentValue:y}=W(s,k);b([N,v],()=>{a&&S(!1)});const $=x=>{if(x.preventDefault(),!u){if(!a){const h=te(N);H({...h,top:h.top+h.height})}S(h=>!h)}},D=Z(()=>!!(u||a||m)),f=t.find(x=>x.value===m),F=n.useMemo(()=>l.jsx("div",{className:g("flex h-5 w-5 transition-all duration-300 ease-in-out",u?"text-white/50":"text-white",a?"rotate-180":"rotate-0",a&&"select-post-adornment-content--showed",u&&"select-post-adornment-content--disabled"),children:(c==null?void 0:c.children)??l.jsx(n.Suspense,{children:l.jsx(A,{name:"chevron-down"})})}),[u,a,c==null?void 0:c.children]),G=n.useCallback(x=>h=>{w==null||w(x,h),S(!1),y(x)},[w,y,S]);return l.jsxs("div",{className:g("relative min-w-52",d?"w-full":"w-fit","select"),...E,children:[l.jsxs("div",{role:"button",ref:N,onClick:$,tabIndex:C,className:g("relative h-14 cursor-pointer rounded transition-all duration-200 ease-in-out",d?"w-full":"w-52",u?"cursor-not-allowed":"cursor-pointer",z.getVariantClasses(e,u),`select-box--variant-${e}`,"select-box",d&&"select-box--full-width",u&&"select-box--disabled",!!o&&"select-box--error"),...I,children:[l.jsx(n.Suspense,{children:!!(i!=null&&i.children)&&l.jsx(P,{...i,required:q,disabled:u,variant:e,isLabelCollapsed:D,isFocused:a,isError:!!o})}),l.jsx("select",{required:q,disabled:u,className:"h-full w-full cursor-pointer opacity-0",...V}),l.jsx("span",{className:g("absolute left-0 box-border w-full overflow-hidden overflow-ellipsis whitespace-nowrap border-none bg-transparent font-sans text-base transition-all duration-200 ease-in-out",i!=null&&i.children?"top-3 h-11 leading-[2.75rem]":"top-0 h-14 leading-[3.5rem]",u?"text-white/50":"text-white",z.getInputPaddingClasses(!1,!!(c!=null&&c.children),e),"select-inner-box",`select-inner-box--variant-${e}`,!!(i!=null&&i.children)&&"select-inner-box--hasLabel",u&&"select-inner-box--disabled"),title:typeof(f==null?void 0:f.label)=="string"?f==null?void 0:f.label:void 0,..._,children:f==null?void 0:f.label}),l.jsx(n.Suspense,{children:!!(c!=null&&c.children)&&l.jsx(p,{...c,variant:e,children:F})}),l.jsx(n.Suspense,{children:!!(r!=null&&r.children)&&l.jsx(T,{...r,isError:!!o,variant:e,children:(o==null?void 0:o.message)??(r==null?void 0:r.children)??""})})]}),l.jsx(X.Portal,{className:"portal-select",children:l.jsx(n.Suspense,{children:a&&l.jsx(ee,{ref:v,options:t,position:B,isShowed:a,currentValue:m,htmlAttributes:M,selectOption:G})})})]})});L.displayName="Select";exports.Select=L;
@@ -0,0 +1,2 @@
1
+ export * from './_components';
2
+ export * from './_types';
package/dist/index.js ADDED
@@ -0,0 +1,201 @@
1
+ import { jsx as c, jsxs as C } from "react/jsx-runtime";
2
+ import g from "clsx";
3
+ import { lazy as w, forwardRef as J, useRef as E, useState as I, useMemo as K, Suspense as r, useCallback as O } from "react";
4
+ import { Portal as Q } from "@purr-core/components.portal";
5
+ import U from "@purr-core/hooks.block";
6
+ import X from "@purr-core/hooks.not-click-on-elements";
7
+ import Z from "@purr-core/hooks.sync-state-with-props";
8
+ import { getVariantClasses as q, getInputPaddingClasses as W } from "@purr-react-tailwindcss/utils.helpers";
9
+ const b = w(
10
+ () => import("@purr-react-tailwindcss/components.helper-text").then((t) => ({
11
+ default: t.HelperText
12
+ }))
13
+ ), T = w(
14
+ () => import("@purr-react-tailwindcss/components.icon").then((t) => ({
15
+ default: t.Icon
16
+ }))
17
+ ), A = w(
18
+ () => import("@purr-react-tailwindcss/components.label").then((t) => ({
19
+ default: t.Label
20
+ }))
21
+ ), P = w(
22
+ () => import("@purr-react-tailwindcss/components.post-adornment").then(
23
+ (t) => ({
24
+ default: t.PostAdornment
25
+ })
26
+ )
27
+ ), p = w(
28
+ () => import("./_menu-CZg5PPUe.js").then((t) => ({ default: t.SelectMenu }))
29
+ ), ee = (t, S = !0) => {
30
+ var i;
31
+ const e = (i = t.current) == null ? void 0 : i.getBoundingClientRect();
32
+ return {
33
+ left: (e == null ? void 0 : e.x) || 0,
34
+ top: ((e == null ? void 0 : e.y) || 0) + (S && (window == null ? void 0 : window.scrollY) || 0),
35
+ width: (e == null ? void 0 : e.width) || 0,
36
+ height: (e == null ? void 0 : e.height) || 0
37
+ };
38
+ }, te = J(
39
+ ({
40
+ options: t,
41
+ value: S,
42
+ variant: e = "standard",
43
+ labelProps: i,
44
+ postAdornmentProps: l,
45
+ helperTextProps: a,
46
+ fullWidth: d = !1,
47
+ disabled: n = !1,
48
+ required: L = !1,
49
+ error: h = null,
50
+ isStandalone: M = !1,
51
+ tabIndex: V = -1,
52
+ menuHtmlAttributes: j,
53
+ htmlAttributes: B,
54
+ boxHtmlAttributes: H,
55
+ fakeSelectHtmlAttributes: $,
56
+ displayedOptionHtmlAttributes: y,
57
+ onChange: m
58
+ }, ce) => {
59
+ const N = E(null), R = E(null), [f, x] = I(!1), [z, D] = I(null), { currentValue: v, setCurrentValue: k } = Z(S, M);
60
+ X([N, R], () => {
61
+ f && x(!1);
62
+ });
63
+ const F = (o) => {
64
+ if (o.preventDefault(), !n) {
65
+ if (!f) {
66
+ const s = ee(N);
67
+ D({
68
+ ...s,
69
+ top: s.top + s.height
70
+ });
71
+ }
72
+ x((s) => !s);
73
+ }
74
+ }, G = U(() => !!(n || f || v)), u = t.find((o) => o.value === v), Y = K(
75
+ () => /* @__PURE__ */ c(
76
+ "div",
77
+ {
78
+ className: g(
79
+ "flex h-5 w-5 transition-all duration-300 ease-in-out",
80
+ n ? "text-white/50" : "text-white",
81
+ f ? "rotate-180" : "rotate-0",
82
+ f && "select-post-adornment-content--showed",
83
+ n && "select-post-adornment-content--disabled"
84
+ ),
85
+ children: (l == null ? void 0 : l.children) ?? /* @__PURE__ */ c(r, { children: /* @__PURE__ */ c(T, { name: "chevron-down" }) })
86
+ }
87
+ ),
88
+ [n, f, l == null ? void 0 : l.children]
89
+ ), _ = O(
90
+ (o) => (s) => {
91
+ m == null || m(o, s), x(!1), k(o);
92
+ },
93
+ [m, k, x]
94
+ );
95
+ return /* @__PURE__ */ C(
96
+ "div",
97
+ {
98
+ className: g(
99
+ "relative min-w-52",
100
+ d ? "w-full" : "w-fit",
101
+ "select"
102
+ ),
103
+ ...B,
104
+ children: [
105
+ /* @__PURE__ */ C(
106
+ "div",
107
+ {
108
+ role: "button",
109
+ ref: N,
110
+ onClick: F,
111
+ tabIndex: V,
112
+ className: g(
113
+ "relative h-14 cursor-pointer rounded transition-all duration-200 ease-in-out",
114
+ d ? "w-full" : "w-52",
115
+ n ? "cursor-not-allowed" : "cursor-pointer",
116
+ q(e, n),
117
+ `select-box--variant-${e}`,
118
+ "select-box",
119
+ d && "select-box--full-width",
120
+ n && "select-box--disabled",
121
+ !!h && "select-box--error"
122
+ ),
123
+ ...H,
124
+ children: [
125
+ /* @__PURE__ */ c(r, { children: !!(i != null && i.children) && /* @__PURE__ */ c(
126
+ A,
127
+ {
128
+ ...i,
129
+ required: L,
130
+ disabled: n,
131
+ variant: e,
132
+ isLabelCollapsed: G,
133
+ isFocused: f,
134
+ isError: !!h
135
+ }
136
+ ) }),
137
+ /* @__PURE__ */ c(
138
+ "select",
139
+ {
140
+ required: L,
141
+ disabled: n,
142
+ className: "h-full w-full cursor-pointer opacity-0",
143
+ ...$
144
+ }
145
+ ),
146
+ /* @__PURE__ */ c(
147
+ "span",
148
+ {
149
+ className: g(
150
+ "absolute left-0 box-border w-full overflow-hidden overflow-ellipsis whitespace-nowrap border-none bg-transparent font-sans text-base transition-all duration-200 ease-in-out",
151
+ i != null && i.children ? "top-3 h-11 leading-[2.75rem]" : "top-0 h-14 leading-[3.5rem]",
152
+ n ? "text-white/50" : "text-white",
153
+ W(
154
+ !1,
155
+ !!(l != null && l.children),
156
+ e
157
+ ),
158
+ "select-inner-box",
159
+ `select-inner-box--variant-${e}`,
160
+ !!(i != null && i.children) && "select-inner-box--hasLabel",
161
+ n && "select-inner-box--disabled"
162
+ ),
163
+ title: typeof (u == null ? void 0 : u.label) == "string" ? u == null ? void 0 : u.label : void 0,
164
+ ...y,
165
+ children: u == null ? void 0 : u.label
166
+ }
167
+ ),
168
+ /* @__PURE__ */ c(r, { children: !!(l != null && l.children) && /* @__PURE__ */ c(P, { ...l, variant: e, children: Y }) }),
169
+ /* @__PURE__ */ c(r, { children: !!(a != null && a.children) && /* @__PURE__ */ c(
170
+ b,
171
+ {
172
+ ...a,
173
+ isError: !!h,
174
+ variant: e,
175
+ children: (h == null ? void 0 : h.message) ?? (a == null ? void 0 : a.children) ?? ""
176
+ }
177
+ ) })
178
+ ]
179
+ }
180
+ ),
181
+ /* @__PURE__ */ c(Q, { className: "portal-select", children: /* @__PURE__ */ c(r, { children: f && /* @__PURE__ */ c(
182
+ p,
183
+ {
184
+ ref: R,
185
+ options: t,
186
+ position: z,
187
+ isShowed: f,
188
+ currentValue: v,
189
+ htmlAttributes: j,
190
+ selectOption: _
191
+ }
192
+ ) }) })
193
+ ]
194
+ }
195
+ );
196
+ }
197
+ );
198
+ te.displayName = "Select";
199
+ export {
200
+ te as Select
201
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@purr-react-tailwindcss/components.select",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "peerDependencies": {
24
+ "typescript": "*",
25
+ "react": "*",
26
+ "clsx": "*",
27
+ "react-hook-form": "*",
28
+ "@purr-core/utils.definitions": "0.0.6",
29
+ "@purr-react-tailwindcss/components.helper-text": "0.0.2",
30
+ "@purr-react-tailwindcss/components.label": "0.0.2",
31
+ "@purr-react-tailwindcss/components.post-adornment": "0.0.2",
32
+ "@purr-react-tailwindcss/components.icon": "0.0.2",
33
+ "@purr-react-tailwindcss/utils.helpers": "0.0.1",
34
+ "@purr-core/components.portal": "0.0.3",
35
+ "@purr-core/hooks.block": "0.0.5",
36
+ "@purr-core/hooks.not-click-on-elements": "0.0.4",
37
+ "@purr-core/hooks.sync-state-with-props": "0.0.4"
38
+ },
39
+ "author": "@DinhThienPhuc",
40
+ "license": "ISC",
41
+ "description": "",
42
+ "sideEffects": false,
43
+ "scripts": {
44
+ "dev": "vite build --watch",
45
+ "build": "tsc && vite build",
46
+ "lint": "eslint . --ext ts,tsx --max-warnings 0"
47
+ }
48
+ }