@purr-react-styled-components/components.text-field 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.
- package/dist/_components.d.ts +4 -0
- package/dist/_style.d.ts +15 -0
- package/dist/_types.d.ts +29 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +81 -0
- package/package.json +49 -0
package/dist/_style.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TTextFieldVariant } from './_types';
|
|
2
|
+
|
|
3
|
+
export declare const Styled: {
|
|
4
|
+
Container: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
|
|
5
|
+
$fullWidth: boolean;
|
|
6
|
+
$disabled: boolean;
|
|
7
|
+
$variant: TTextFieldVariant;
|
|
8
|
+
}>> & string;
|
|
9
|
+
Input: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, {
|
|
10
|
+
$variant: TTextFieldVariant;
|
|
11
|
+
$hasPreAdornment: boolean;
|
|
12
|
+
$hasPostAdornment: boolean;
|
|
13
|
+
$hasLabel: boolean;
|
|
14
|
+
}>> & string;
|
|
15
|
+
};
|
package/dist/_types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEventHandler, HTMLAttributes, InputHTMLAttributes } from 'react';
|
|
2
|
+
import { FieldError } from 'react-hook-form';
|
|
3
|
+
import { IExtendable } from '@purr-core/utils.definitions';
|
|
4
|
+
import { IHelperTextProps } from '@purr-react-styled-components/components.helper-text';
|
|
5
|
+
import { ILabelProps } from '@purr-react-styled-components/components.label';
|
|
6
|
+
import { IPostAdornmentProps } from '@purr-react-styled-components/components.post-adornment';
|
|
7
|
+
import { IPreAdornmentProps } from '@purr-react-styled-components/components.pre-adornment';
|
|
8
|
+
|
|
9
|
+
export type TTextFieldVariant = "standard" | "outlined" | "filled";
|
|
10
|
+
export interface ITextFieldProps {
|
|
11
|
+
value?: string;
|
|
12
|
+
variant?: TTextFieldVariant;
|
|
13
|
+
onChange?: (value: string, e: ChangeEvent<HTMLInputElement>) => void;
|
|
14
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
15
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
16
|
+
clear?: () => void;
|
|
17
|
+
htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
|
|
18
|
+
inputHtmlAttributes?: InputHTMLAttributes<HTMLInputElement> & IExtendable;
|
|
19
|
+
labelProps?: ILabelProps;
|
|
20
|
+
preAdornmentProps?: IPreAdornmentProps;
|
|
21
|
+
postAdornmentProps?: IPostAdornmentProps;
|
|
22
|
+
helperTextProps?: IHelperTextProps;
|
|
23
|
+
className?: string;
|
|
24
|
+
fullWidth?: boolean;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
error?: FieldError;
|
|
28
|
+
isStandalone?: boolean;
|
|
29
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var H=Object.create;var q=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var G=(i,t,e,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of W(t))!D.call(i,d)&&d!==e&&q(i,d,{get:()=>t[d],enumerable:!(l=M(t,d))||l.enumerable});return i};var g=(i,t,e)=>(e=i!=null?H(b(i)):{},G(t||!i||!i.__esModule?q(e,"default",{value:i,enumerable:!0}):e,i));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),w=require("clsx"),u=require("react"),J=require("@purr-core/hooks.focus-with-callback"),K=require("@purr-core/hooks.sync-state-with-props"),S=require("styled-components"),Q=require("@purr-react-styled-components/utils.helpers"),U=i=>{let t=0,e=0;const l=(i==null?void 0:i.$variant)==="standard"?0:14;return i!=null&&i.$hasPreAdornment?t=32+l:t=l,i!=null&&i.$hasPostAdornment?e=32+l:e=l,S.css(["padding:0px ","px 0px ","px;"],e,t)},z={Container:S.div.withConfig({displayName:"_style__Container",componentId:"sc-8htvm-0"})(["transition:all 200ms ease-in-out;position:relative;width:",";height:56px;border-radius:4px;",";"],({$fullWidth:i})=>i?"100%":"210px",Q.getVariantStyle),Input:S.input.withConfig({displayName:"_style__Input",componentId:"sc-8htvm-1"})(["box-sizing:border-box;transition:all 200ms ease-in-out;width:100%;margin-top:",";height:",";line-height:",";background-color:transparent;color:#ffffff;border-radius:4px;border:none;font-size:16px;",";&:focus-visible{outline:none;}&:disabled{color:#ffffff80;}"],({$hasLabel:i})=>i?"12px":"0px",({$hasLabel:i})=>i?"44px":"56px",({$hasLabel:i})=>i?"44px":"56px",U)},X=u.lazy(()=>import("@purr-react-styled-components/components.helper-text").then(i=>({default:i.HelperText}))),Y=u.lazy(()=>import("@purr-react-styled-components/components.label").then(i=>({default:i.Label}))),Z=u.lazy(()=>import("@purr-react-styled-components/components.post-adornment").then(i=>({default:i.PostAdornment}))),T=u.lazy(()=>import("@purr-react-styled-components/components.pre-adornment").then(i=>({default:i.PreAdornment}))),C=u.forwardRef(({value:i="",variant:t="standard",onChange:e,onFocus:l,onBlur:d,clear:$,htmlAttributes:L,inputHtmlAttributes:I,labelProps:n,preAdornmentProps:c,postAdornmentProps:f,helperTextProps:x,className:N="",fullWidth:v=!1,disabled:h=!1,required:y=!1,error:s=null,isStandalone:O=!1},R)=>{const{currentValue:F,setCurrentValue:V}=K(i,O),{captureOnFocus:k,captureOnBlur:m,isFocused:_}=J({onFocus:l,onBlur:d}),B=!!(_||c!=null&&c.children||F),E=j=>{e==null||e(j.target.value,j),V(j.target.value)};return a.jsxs(z.Container,{...L,$fullWidth:v,$variant:t,$disabled:h,className:w("text-field",v&&"text-field--full-width",y&&"text-field--required",h&&"text-field--disabled",s&&"text-field--error",`text-field--variant-${t}`,N),children:[a.jsx(u.Suspense,{children:!!(n!=null&&n.children)&&a.jsx(Y,{...n,variant:t,disabled:h,required:y,isLabelCollapsed:B,isFocused:_,isError:!!s})}),a.jsx(u.Suspense,{children:!!(c!=null&&c.children)&&a.jsx(T,{...c,hasLabel:!!(n!=null&&n.children),variant:t})}),a.jsx(z.Input,{...I,$variant:t,$hasPreAdornment:!!(c!=null&&c.children),$hasPostAdornment:!!$||!!(f!=null&&f.children),$hasLabel:!!(n!=null&&n.children),ref:R,value:F,disabled:h,required:y,onChange:E,onFocus:k,onBlur:m,className:w("text-field-input",`text-field-input--variant-${t}`,h&&"text-field-input--disabled",y&&"text-field-input--required")}),a.jsx(u.Suspense,{children:!!(f!=null&&f.children)&&a.jsx(Z,{...f,clear:$,variant:t})}),a.jsx(u.Suspense,{children:(x==null?void 0:x.children)&&a.jsx(X,{...x,isError:!!s,variant:t,children:(s==null?void 0:s.message)??(x==null?void 0:x.children)??""})})]})});C.displayName="TextField";exports.TextField=C;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsxs as O, jsx as f } from "react/jsx-runtime";
|
|
2
|
+
import w from "clsx";
|
|
3
|
+
import { lazy as m, forwardRef as R, Suspense as g } from "react";
|
|
4
|
+
import W from "@purr-core/hooks.focus-with-callback";
|
|
5
|
+
import M from "@purr-core/hooks.sync-state-with-props";
|
|
6
|
+
import C, { css as D } from "styled-components";
|
|
7
|
+
import { getVariantStyle as G } from "@purr-react-styled-components/utils.helpers";
|
|
8
|
+
const J = (i) => {
|
|
9
|
+
let t = 0, n = 0;
|
|
10
|
+
const l = (i == null ? void 0 : i.$variant) === "standard" ? 0 : 14;
|
|
11
|
+
return i != null && i.$hasPreAdornment ? t = 32 + l : t = l, i != null && i.$hasPostAdornment ? n = 32 + l : n = l, D(["padding:0px ", "px 0px ", "px;"], n, t);
|
|
12
|
+
}, F = {
|
|
13
|
+
Container: C.div.withConfig({
|
|
14
|
+
displayName: "_style__Container",
|
|
15
|
+
componentId: "sc-8htvm-0"
|
|
16
|
+
})(["transition:all 200ms ease-in-out;position:relative;width:", ";height:56px;border-radius:4px;", ";"], ({
|
|
17
|
+
$fullWidth: i
|
|
18
|
+
}) => i ? "100%" : "210px", G),
|
|
19
|
+
Input: C.input.withConfig({
|
|
20
|
+
displayName: "_style__Input",
|
|
21
|
+
componentId: "sc-8htvm-1"
|
|
22
|
+
})(["box-sizing:border-box;transition:all 200ms ease-in-out;width:100%;margin-top:", ";height:", ";line-height:", ";background-color:transparent;color:#ffffff;border-radius:4px;border:none;font-size:16px;", ";&:focus-visible{outline:none;}&:disabled{color:#ffffff80;}"], ({
|
|
23
|
+
$hasLabel: i
|
|
24
|
+
}) => i ? "12px" : "0px", ({
|
|
25
|
+
$hasLabel: i
|
|
26
|
+
}) => i ? "44px" : "56px", ({
|
|
27
|
+
$hasLabel: i
|
|
28
|
+
}) => i ? "44px" : "56px", J)
|
|
29
|
+
}, K = m(() => import("@purr-react-styled-components/components.helper-text").then((i) => ({
|
|
30
|
+
default: i.HelperText
|
|
31
|
+
}))), Q = m(() => import("@purr-react-styled-components/components.label").then((i) => ({
|
|
32
|
+
default: i.Label
|
|
33
|
+
}))), U = m(() => import("@purr-react-styled-components/components.post-adornment").then((i) => ({
|
|
34
|
+
default: i.PostAdornment
|
|
35
|
+
}))), X = m(() => import("@purr-react-styled-components/components.pre-adornment").then((i) => ({
|
|
36
|
+
default: i.PreAdornment
|
|
37
|
+
}))), Y = R(({
|
|
38
|
+
value: i = "",
|
|
39
|
+
variant: t = "standard",
|
|
40
|
+
onChange: n,
|
|
41
|
+
onFocus: l,
|
|
42
|
+
onBlur: L,
|
|
43
|
+
clear: $,
|
|
44
|
+
htmlAttributes: _,
|
|
45
|
+
inputHtmlAttributes: I,
|
|
46
|
+
labelProps: a,
|
|
47
|
+
preAdornmentProps: e,
|
|
48
|
+
postAdornmentProps: c,
|
|
49
|
+
helperTextProps: d,
|
|
50
|
+
className: N = "",
|
|
51
|
+
fullWidth: s = !1,
|
|
52
|
+
disabled: h = !1,
|
|
53
|
+
required: x = !1,
|
|
54
|
+
error: u = null,
|
|
55
|
+
isStandalone: z = !1
|
|
56
|
+
}, V) => {
|
|
57
|
+
const {
|
|
58
|
+
currentValue: S,
|
|
59
|
+
setCurrentValue: j
|
|
60
|
+
} = M(i, z), {
|
|
61
|
+
captureOnFocus: k,
|
|
62
|
+
captureOnBlur: B,
|
|
63
|
+
isFocused: v
|
|
64
|
+
} = W({
|
|
65
|
+
onFocus: l,
|
|
66
|
+
onBlur: L
|
|
67
|
+
}), E = !!(v || e != null && e.children || S), H = (y) => {
|
|
68
|
+
n == null || n(y.target.value, y), j(y.target.value);
|
|
69
|
+
};
|
|
70
|
+
return /* @__PURE__ */ O(F.Container, { ..._, $fullWidth: s, $variant: t, $disabled: h, className: w("text-field", s && "text-field--full-width", x && "text-field--required", h && "text-field--disabled", u && "text-field--error", `text-field--variant-${t}`, N), children: [
|
|
71
|
+
/* @__PURE__ */ f(g, { children: !!(a != null && a.children) && /* @__PURE__ */ f(Q, { ...a, variant: t, disabled: h, required: x, isLabelCollapsed: E, isFocused: v, isError: !!u }) }),
|
|
72
|
+
/* @__PURE__ */ f(g, { children: !!(e != null && e.children) && /* @__PURE__ */ f(X, { ...e, hasLabel: !!(a != null && a.children), variant: t }) }),
|
|
73
|
+
/* @__PURE__ */ f(F.Input, { ...I, $variant: t, $hasPreAdornment: !!(e != null && e.children), $hasPostAdornment: !!$ || !!(c != null && c.children), $hasLabel: !!(a != null && a.children), ref: V, value: S, disabled: h, required: x, onChange: H, onFocus: k, onBlur: B, className: w("text-field-input", `text-field-input--variant-${t}`, h && "text-field-input--disabled", x && "text-field-input--required") }),
|
|
74
|
+
/* @__PURE__ */ f(g, { children: !!(c != null && c.children) && /* @__PURE__ */ f(U, { ...c, clear: $, variant: t }) }),
|
|
75
|
+
/* @__PURE__ */ f(g, { children: (d == null ? void 0 : d.children) && /* @__PURE__ */ f(K, { ...d, isError: !!u, variant: t, children: (u == null ? void 0 : u.message) ?? (d == null ? void 0 : d.children) ?? "" }) })
|
|
76
|
+
] });
|
|
77
|
+
});
|
|
78
|
+
Y.displayName = "TextField";
|
|
79
|
+
export {
|
|
80
|
+
Y as TextField
|
|
81
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purr-react-styled-components/components.text-field",
|
|
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
|
+
"styled-components": "*",
|
|
27
|
+
"clsx": "*",
|
|
28
|
+
"@purr-react-styled-components/components.helper-text": "0.0.1",
|
|
29
|
+
"@purr-react-styled-components/components.label": "0.0.1",
|
|
30
|
+
"@purr-react-styled-components/components.post-adornment": "0.0.1",
|
|
31
|
+
"@purr-react-styled-components/components.pre-adornment": "0.0.1",
|
|
32
|
+
"@purr-core/utils.definitions": "0.0.4",
|
|
33
|
+
"@purr-react-styled-components/utils.helpers": "0.0.1",
|
|
34
|
+
"@purr-core/hooks.focus-with-callback": "0.0.2",
|
|
35
|
+
"@purr-core/hooks.sync-state-with-props": "0.0.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@purr-react-styled-components/components.icon": "0.0.1"
|
|
39
|
+
},
|
|
40
|
+
"author": "@DinhThienPhuc",
|
|
41
|
+
"license": "ISC",
|
|
42
|
+
"description": "",
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "vite build --watch",
|
|
46
|
+
"build": "tsc && vite build",
|
|
47
|
+
"lint": "eslint . --ext ts,tsx --max-warnings 0"
|
|
48
|
+
}
|
|
49
|
+
}
|