@purr-react-tailwindcss/components.select 0.0.5 → 0.0.7
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/dist/index.cjs +1 -1
- package/dist/{_types.d.ts → index.d.cts} +10 -6
- package/dist/index.d.ts +55 -2
- package/dist/index.js +1 -201
- package/package.json +13 -11
- package/dist/_components/_menu.d.ts +0 -4
- package/dist/_components/_option.d.ts +0 -4
- package/dist/_components/index.d.ts +0 -4
- package/dist/_menu-CZg5PPUe.js +0 -72
- package/dist/_menu-CedOsSIk.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';var b=require('clsx'),n=require('react'),components_portal=require('@purr-core/components.portal'),le=require('@purr-core/hooks.block'),re=require('@purr-core/hooks.not-click-on-elements'),se=require('@purr-core/hooks.sync-state-with-props'),utils_helpers=require('@purr-react-tailwindcss/utils.helpers');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var b__default=/*#__PURE__*/_interopDefault(b);var n__default=/*#__PURE__*/_interopDefault(n);var le__default=/*#__PURE__*/_interopDefault(le);var re__default=/*#__PURE__*/_interopDefault(re);var se__default=/*#__PURE__*/_interopDefault(se);var J=Object.defineProperty;var E=(e,o)=>()=>(e&&(o=e(e=0)),o);var K=(e,o)=>{for(var t in o)J(e,t,{get:o[t],enumerable:true});};var v,L=E(()=>{v=n.memo(({value:e,displayedValue:o,label:t,disabled:r,htmlAttributes:s,handleSelectOption:a})=>n__default.default.createElement("button",{className:b__default.default("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&&e===o&&"bg-sky-400/20 text-white",!r&&e!==o&&"bg-transparent text-white","select-option",e===o&&"select-option--selected",r&&"select-option--disabled"),onClick:a(e),...s,title:typeof t=="string"?t:void 0},t));v.displayName="SelectOption";});var H={};K(H,{SelectMenu:()=>_});var _,I=E(()=>{L();_=n.forwardRef(({options:e,position:o,isShowed:t,currentValue:r,htmlAttributes:s,selectOption:a},f)=>{let l=n.useMemo(()=>e.map(u=>n__default.default.createElement(v,{key:u.value,value:u.value,displayedValue:r,label:u.label,disabled:!!u.disabled,htmlAttributes:u.htmlAttributes,handleSelectOption:a})),[r,e,a]);return n__default.default.createElement("div",{ref:f,className:b__default.default("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]",t?"block":"hidden","select-options",t&&"select-options--showed"),style:{top:`${o?.top||0}px`,left:`${o?.left||0}px`,width:`${o?.width||0}px`},...s},l)});_.displayName="SelectMenu";});var ue=n.lazy(()=>import('@purr-react-tailwindcss/components.helper-text').then(e=>({default:e.HelperText}))),pe=n.lazy(()=>import('@purr-react-tailwindcss/components.icon').then(e=>({default:e.Icon}))),ce=n.lazy(()=>import('@purr-react-tailwindcss/components.label').then(e=>({default:e.Label}))),fe=n.lazy(()=>import('@purr-react-tailwindcss/components.post-adornment').then(e=>({default:e.PostAdornment}))),me=n.lazy(()=>Promise.resolve().then(()=>(I(),H)).then(e=>({default:e.SelectMenu}))),de=(e,o=true)=>{let t=e.current?.getBoundingClientRect();return {left:t?.x||0,top:(t?.y||0)+(o&&window?.scrollY||0),width:t?.width||0,height:t?.height||0}},he=n.forwardRef(({options:e,value:o,variant:t="standard",labelProps:r,postAdornmentProps:s,helperTextProps:a,fullWidth:f=false,disabled:l=false,required:u=false,error:h=null,isStandalone:T=false,tabIndex:P=-1,menuHtmlAttributes:D,htmlAttributes:$,boxHtmlAttributes:A,fakeSelectHtmlAttributes:j,displayedOptionHtmlAttributes:z,onChange:M},xe)=>{let w=n.useRef(null),O=n.useRef(null),[i,x]=n.useState(false),[B,V]=n.useState(null),{currentValue:S,setCurrentValue:y}=se__default.default(o,T);re__default.default([w,O],()=>{i&&x(false);});let q=c=>{if(c.preventDefault(),!l){if(!i){let p=de(w);V({...p,top:p.top+p.height});}x(p=>!p);}},F=le__default.default(()=>!!(l||i||S)),g=e.find(c=>c.value===S),G=n.useMemo(()=>n__default.default.createElement("div",{className:b__default.default("flex h-5 w-5 transition-all duration-300 ease-in-out",l?"text-white/50":"text-white",i?"rotate-180":"rotate-0",i&&"select-post-adornment-content--showed",l&&"select-post-adornment-content--disabled")},s?.children??n__default.default.createElement(n.Suspense,null,n__default.default.createElement(pe,{name:"chevron-down"}))),[l,i,s?.children]),Y=n.useCallback(c=>p=>{M?.(c,p),x(false),y(c);},[M,y,x]);return n__default.default.createElement("div",{className:b__default.default("relative min-w-52",f?"w-full":"w-fit","select"),...$},n__default.default.createElement("div",{role:"button",ref:w,onClick:q,tabIndex:P,className:b__default.default("relative h-14 cursor-pointer rounded transition-all duration-200 ease-in-out",f?"w-full":"w-52",l?"cursor-not-allowed":"cursor-pointer",utils_helpers.getVariantClasses(t,l),`select-box--variant-${t}`,"select-box",f&&"select-box--full-width",l&&"select-box--disabled",!!h&&"select-box--error"),...A},n__default.default.createElement(n.Suspense,null,!!r?.children&&n__default.default.createElement(ce,{...r,required:u,disabled:l,variant:t,isLabelCollapsed:F,isFocused:i,isError:!!h})),n__default.default.createElement("select",{required:u,disabled:l,className:"h-full w-full cursor-pointer opacity-0",...j}),n__default.default.createElement("span",{className:b__default.default("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",r?.children?"top-3 h-11 leading-[2.75rem]":"top-0 h-14 leading-[3.5rem]",l?"text-white/50":"text-white",utils_helpers.getInputPaddingClasses(false,!!s?.children,t),"select-inner-box",`select-inner-box--variant-${t}`,!!r?.children&&"select-inner-box--hasLabel",l&&"select-inner-box--disabled"),title:typeof g?.label=="string"?g?.label:void 0,...z},g?.label),n__default.default.createElement(n.Suspense,null,!!s?.children&&n__default.default.createElement(fe,{...s,variant:t},G)),n__default.default.createElement(n.Suspense,null,!!a?.children&&n__default.default.createElement(ue,{...a,isError:!!h,variant:t},h?.message??a?.children??""))),n__default.default.createElement(components_portal.Portal,{className:"portal-select"},n__default.default.createElement(n.Suspense,null,i&&n__default.default.createElement(me,{ref:O,options:e,position:B,isShowed:i,currentValue:S,htmlAttributes:D,selectOption:Y}))))});he.displayName="Select";exports.Select=he;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { HTMLAttributes, MouseEvent, MouseEventHandler
|
|
1
|
+
import React, { ReactNode, HTMLAttributes, MouseEvent, MouseEventHandler } from 'react';
|
|
2
2
|
import { FieldError } from 'react-hook-form';
|
|
3
3
|
import { IExtendable } from '@purr-core/utils.definitions';
|
|
4
4
|
import { IHelperTextProps } from '@purr-react-tailwindcss/components.helper-text';
|
|
5
5
|
import { ILabelProps } from '@purr-react-tailwindcss/components.label';
|
|
6
6
|
import { IPostAdornmentProps } from '@purr-react-tailwindcss/components.post-adornment';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface ISelectOption {
|
|
9
9
|
value: string;
|
|
10
10
|
label: ReactNode;
|
|
11
11
|
disabled?: boolean;
|
|
12
12
|
htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
interface ISelectOptionProps extends ISelectOption {
|
|
15
15
|
displayedValue?: string;
|
|
16
16
|
handleSelectOption: (value: string) => MouseEventHandler<HTMLSpanElement>;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
type TSelectVariant = "standard" | "outlined" | "filled";
|
|
19
|
+
interface ISelectMenuProps {
|
|
20
20
|
options: ISelectOption[];
|
|
21
21
|
position: {
|
|
22
22
|
left: number;
|
|
@@ -29,7 +29,7 @@ export interface ISelectMenuProps {
|
|
|
29
29
|
htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
|
|
30
30
|
selectOption: (value: string) => MouseEventHandler<HTMLSpanElement>;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
interface ISelectProps {
|
|
33
33
|
options: ISelectOption[];
|
|
34
34
|
value?: string;
|
|
35
35
|
variant?: TSelectVariant;
|
|
@@ -49,3 +49,7 @@ export interface ISelectProps {
|
|
|
49
49
|
isStandalone?: boolean;
|
|
50
50
|
onChange?: (value: string, e: MouseEvent<HTMLSpanElement>) => void;
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
declare const Select: React.ForwardRefExoticComponent<ISelectProps & React.RefAttributes<HTMLSelectElement>>;
|
|
54
|
+
|
|
55
|
+
export { type ISelectMenuProps, type ISelectOption, type ISelectOptionProps, type ISelectProps, Select, type TSelectVariant };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React, { ReactNode, HTMLAttributes, MouseEvent, MouseEventHandler } 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
|
+
interface ISelectOption {
|
|
9
|
+
value: string;
|
|
10
|
+
label: ReactNode;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
13
|
+
}
|
|
14
|
+
interface ISelectOptionProps extends ISelectOption {
|
|
15
|
+
displayedValue?: string;
|
|
16
|
+
handleSelectOption: (value: string) => MouseEventHandler<HTMLSpanElement>;
|
|
17
|
+
}
|
|
18
|
+
type TSelectVariant = "standard" | "outlined" | "filled";
|
|
19
|
+
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
|
+
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
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const Select: React.ForwardRefExoticComponent<ISelectProps & React.RefAttributes<HTMLSelectElement>>;
|
|
54
|
+
|
|
55
|
+
export { type ISelectMenuProps, type ISelectOption, type ISelectOptionProps, type ISelectProps, Select, type TSelectVariant };
|
package/dist/index.js
CHANGED
|
@@ -1,201 +1 @@
|
|
|
1
|
-
import {
|
|
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
|
-
};
|
|
1
|
+
import b from'clsx';import n,{lazy,forwardRef,useRef,useState,useMemo,Suspense,useCallback,memo}from'react';import {Portal}from'@purr-core/components.portal';import le from'@purr-core/hooks.block';import re from'@purr-core/hooks.not-click-on-elements';import se from'@purr-core/hooks.sync-state-with-props';import {getVariantClasses,getInputPaddingClasses}from'@purr-react-tailwindcss/utils.helpers';var J=Object.defineProperty;var E=(e,o)=>()=>(e&&(o=e(e=0)),o);var K=(e,o)=>{for(var t in o)J(e,t,{get:o[t],enumerable:true});};var v,L=E(()=>{v=memo(({value:e,displayedValue:o,label:t,disabled:r,htmlAttributes:s,handleSelectOption:a})=>n.createElement("button",{className:b("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&&e===o&&"bg-sky-400/20 text-white",!r&&e!==o&&"bg-transparent text-white","select-option",e===o&&"select-option--selected",r&&"select-option--disabled"),onClick:a(e),...s,title:typeof t=="string"?t:void 0},t));v.displayName="SelectOption";});var H={};K(H,{SelectMenu:()=>_});var _,I=E(()=>{L();_=forwardRef(({options:e,position:o,isShowed:t,currentValue:r,htmlAttributes:s,selectOption:a},f)=>{let l=useMemo(()=>e.map(u=>n.createElement(v,{key:u.value,value:u.value,displayedValue:r,label:u.label,disabled:!!u.disabled,htmlAttributes:u.htmlAttributes,handleSelectOption:a})),[r,e,a]);return n.createElement("div",{ref:f,className:b("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]",t?"block":"hidden","select-options",t&&"select-options--showed"),style:{top:`${o?.top||0}px`,left:`${o?.left||0}px`,width:`${o?.width||0}px`},...s},l)});_.displayName="SelectMenu";});var ue=lazy(()=>import('@purr-react-tailwindcss/components.helper-text').then(e=>({default:e.HelperText}))),pe=lazy(()=>import('@purr-react-tailwindcss/components.icon').then(e=>({default:e.Icon}))),ce=lazy(()=>import('@purr-react-tailwindcss/components.label').then(e=>({default:e.Label}))),fe=lazy(()=>import('@purr-react-tailwindcss/components.post-adornment').then(e=>({default:e.PostAdornment}))),me=lazy(()=>Promise.resolve().then(()=>(I(),H)).then(e=>({default:e.SelectMenu}))),de=(e,o=true)=>{let t=e.current?.getBoundingClientRect();return {left:t?.x||0,top:(t?.y||0)+(o&&window?.scrollY||0),width:t?.width||0,height:t?.height||0}},he=forwardRef(({options:e,value:o,variant:t="standard",labelProps:r,postAdornmentProps:s,helperTextProps:a,fullWidth:f=false,disabled:l=false,required:u=false,error:h=null,isStandalone:T=false,tabIndex:P=-1,menuHtmlAttributes:D,htmlAttributes:$,boxHtmlAttributes:A,fakeSelectHtmlAttributes:j,displayedOptionHtmlAttributes:z,onChange:M},xe)=>{let w=useRef(null),O=useRef(null),[i,x]=useState(false),[B,V]=useState(null),{currentValue:S,setCurrentValue:y}=se(o,T);re([w,O],()=>{i&&x(false);});let q=c=>{if(c.preventDefault(),!l){if(!i){let p=de(w);V({...p,top:p.top+p.height});}x(p=>!p);}},F=le(()=>!!(l||i||S)),g=e.find(c=>c.value===S),G=useMemo(()=>n.createElement("div",{className:b("flex h-5 w-5 transition-all duration-300 ease-in-out",l?"text-white/50":"text-white",i?"rotate-180":"rotate-0",i&&"select-post-adornment-content--showed",l&&"select-post-adornment-content--disabled")},s?.children??n.createElement(Suspense,null,n.createElement(pe,{name:"chevron-down"}))),[l,i,s?.children]),Y=useCallback(c=>p=>{M?.(c,p),x(false),y(c);},[M,y,x]);return n.createElement("div",{className:b("relative min-w-52",f?"w-full":"w-fit","select"),...$},n.createElement("div",{role:"button",ref:w,onClick:q,tabIndex:P,className:b("relative h-14 cursor-pointer rounded transition-all duration-200 ease-in-out",f?"w-full":"w-52",l?"cursor-not-allowed":"cursor-pointer",getVariantClasses(t,l),`select-box--variant-${t}`,"select-box",f&&"select-box--full-width",l&&"select-box--disabled",!!h&&"select-box--error"),...A},n.createElement(Suspense,null,!!r?.children&&n.createElement(ce,{...r,required:u,disabled:l,variant:t,isLabelCollapsed:F,isFocused:i,isError:!!h})),n.createElement("select",{required:u,disabled:l,className:"h-full w-full cursor-pointer opacity-0",...j}),n.createElement("span",{className:b("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",r?.children?"top-3 h-11 leading-[2.75rem]":"top-0 h-14 leading-[3.5rem]",l?"text-white/50":"text-white",getInputPaddingClasses(false,!!s?.children,t),"select-inner-box",`select-inner-box--variant-${t}`,!!r?.children&&"select-inner-box--hasLabel",l&&"select-inner-box--disabled"),title:typeof g?.label=="string"?g?.label:void 0,...z},g?.label),n.createElement(Suspense,null,!!s?.children&&n.createElement(fe,{...s,variant:t},G)),n.createElement(Suspense,null,!!a?.children&&n.createElement(ue,{...a,isError:!!h,variant:t},h?.message??a?.children??""))),n.createElement(Portal,{className:"portal-select"},n.createElement(Suspense,null,i&&n.createElement(me,{ref:O,options:e,position:B,isShowed:i,currentValue:S,htmlAttributes:D,selectOption:Y}))))});he.displayName="Select";export{he as Select};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purr-react-tailwindcss/components.select",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"react": "*",
|
|
26
26
|
"clsx": "*",
|
|
27
27
|
"react-hook-form": "*",
|
|
28
|
-
"@purr-core/utils.definitions": "0.0.
|
|
29
|
-
"@purr-react-tailwindcss/components.helper-text": "0.0.
|
|
30
|
-
"@purr-react-tailwindcss/components.label": "0.0.
|
|
31
|
-
"@purr-react-tailwindcss/components.post-adornment": "0.0.
|
|
32
|
-
"@purr-react-tailwindcss/components.icon": "0.0.
|
|
33
|
-
"@purr-react-tailwindcss/utils.helpers": "0.0.
|
|
34
|
-
"@purr-core/components.portal": "0.0.
|
|
35
|
-
"@purr-core/hooks.block": "0.0.
|
|
36
|
-
"@purr-core/hooks.not-click-on-elements": "0.0.
|
|
37
|
-
"@purr-core/hooks.sync-state-with-props": "0.0.
|
|
28
|
+
"@purr-core/utils.definitions": "0.0.12",
|
|
29
|
+
"@purr-react-tailwindcss/components.helper-text": "0.0.8",
|
|
30
|
+
"@purr-react-tailwindcss/components.label": "0.0.8",
|
|
31
|
+
"@purr-react-tailwindcss/components.post-adornment": "0.0.8",
|
|
32
|
+
"@purr-react-tailwindcss/components.icon": "0.0.8",
|
|
33
|
+
"@purr-react-tailwindcss/utils.helpers": "0.0.6",
|
|
34
|
+
"@purr-core/components.portal": "0.0.9",
|
|
35
|
+
"@purr-core/hooks.block": "0.0.11",
|
|
36
|
+
"@purr-core/hooks.not-click-on-elements": "0.0.9",
|
|
37
|
+
"@purr-core/hooks.sync-state-with-props": "0.0.9"
|
|
38
38
|
},
|
|
39
39
|
"author": "@DinhThienPhuc",
|
|
40
40
|
"license": "ISC",
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "vite build --watch",
|
|
45
45
|
"build": "tsc && vite build",
|
|
46
|
+
"build:vite": "tsc && vite build",
|
|
47
|
+
"build:tsup": "tsup",
|
|
46
48
|
"lint": "eslint . --ext ts,tsx --max-warnings 0"
|
|
47
49
|
}
|
|
48
50
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|
package/dist/_menu-CZg5PPUe.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/_menu-CedOsSIk.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;
|