@chayns-components/core 5.0.0-beta.41 → 5.0.0-beta.43
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/lib/components/input/Input.d.ts +4 -0
- package/lib/components/input/Input.js +4 -1
- package/lib/components/input/Input.js.map +1 -1
- package/lib/components/input/Input.styles.d.ts +2 -1
- package/lib/components/input/Input.styles.js +10 -2
- package/lib/components/input/Input.styles.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ChangeEventHandler, FC, FocusEventHandler, HTMLInputTypeAttribute, KeyboardEventHandler } from 'react';
|
|
2
2
|
export declare type InputProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Disables the input so that it cannot be changed anymore
|
|
5
|
+
*/
|
|
6
|
+
isDisabled?: boolean;
|
|
3
7
|
/**
|
|
4
8
|
* Function that is executed when the input field loses focus
|
|
5
9
|
*/
|
|
@@ -10,6 +10,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
10
10
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
11
|
const Input = _ref => {
|
|
12
12
|
let {
|
|
13
|
+
isDisabled,
|
|
13
14
|
onBlur,
|
|
14
15
|
onChange,
|
|
15
16
|
onFocus,
|
|
@@ -43,8 +44,10 @@ const Input = _ref => {
|
|
|
43
44
|
};
|
|
44
45
|
}, [hasValue]);
|
|
45
46
|
return /*#__PURE__*/_react.default.createElement(_Input.StyledInput, {
|
|
46
|
-
className: "beta-chayns-input"
|
|
47
|
+
className: "beta-chayns-input",
|
|
48
|
+
isDisabled: isDisabled
|
|
47
49
|
}, /*#__PURE__*/_react.default.createElement(_Input.StyledInputContent, null, /*#__PURE__*/_react.default.createElement(_Input.StyledInputField, {
|
|
50
|
+
disabled: isDisabled,
|
|
48
51
|
onBlur: onBlur,
|
|
49
52
|
onChange: handleInputFieldChange,
|
|
50
53
|
onFocus: onFocus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","names":["Input","onBlur","onChange","onFocus","onKeyDown","placeholder","type","value","hasValue","setHasValue","useState","handleInputFieldChange","useCallback","event","target","useEffect","labelPosition","useMemo","bottom","right","left","top","scale","originX","originY","displayName"],"sources":["../../../src/components/input/Input.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n FocusEventHandler,\n HTMLInputTypeAttribute,\n KeyboardEventHandler,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport {\n StyledInput,\n StyledInputContent,\n StyledInputField,\n StyledMotionInputLabel,\n} from './Input.styles';\n\nexport type InputProps = {\n /**\n * Function that is executed when the input field loses focus\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the text of the input changes\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLInputElement>;\n /**\n * Placeholder for the input field\n */\n placeholder?: string;\n /**\n * Input type set for input element (e.g. 'text', 'number' or 'password')\n */\n type?: HTMLInputTypeAttribute;\n /**\n * Value if the input field should be controlled\n */\n value?: string;\n};\n\nconst Input: FC<InputProps> = ({\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n placeholder,\n type = 'text',\n value,\n}) => {\n const [hasValue, setHasValue] = useState(typeof value === 'string' && value !== '');\n\n const handleInputFieldChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setHasValue(event.target.value !== '');\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [onChange]\n );\n\n useEffect(() => {\n if (typeof value === 'string') {\n setHasValue(value !== '');\n }\n }, [value]);\n\n const labelPosition = useMemo(() => {\n if (hasValue) {\n return { bottom: -8, right: -6 };\n }\n\n return { left: 0, top: 0 };\n }, [hasValue]);\n\n return (\n <StyledInput className=\"beta-chayns-input\">\n <StyledInputContent>\n <StyledInputField\n onBlur={onBlur}\n onChange={handleInputFieldChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n value={value}\n type={type}\n />\n <StyledMotionInputLabel\n animate={{ scale: hasValue ? 0.6 : 1 }}\n layout\n style={{ ...labelPosition, originX: 1, originY: 1 }}\n transition={{ type: 'tween' }}\n >\n {placeholder}\n </StyledMotionInputLabel>\n </StyledInputContent>\n </StyledInput>\n );\n};\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"mappings":";;;;;;AAAA;AAYA;AAKwB;AAAA;
|
|
1
|
+
{"version":3,"file":"Input.js","names":["Input","isDisabled","onBlur","onChange","onFocus","onKeyDown","placeholder","type","value","hasValue","setHasValue","useState","handleInputFieldChange","useCallback","event","target","useEffect","labelPosition","useMemo","bottom","right","left","top","scale","originX","originY","displayName"],"sources":["../../../src/components/input/Input.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n FocusEventHandler,\n HTMLInputTypeAttribute,\n KeyboardEventHandler,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport {\n StyledInput,\n StyledInputContent,\n StyledInputField,\n StyledMotionInputLabel,\n} from './Input.styles';\n\nexport type InputProps = {\n /**\n * Disables the input so that it cannot be changed anymore\n */\n isDisabled?: boolean;\n /**\n * Function that is executed when the input field loses focus\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the text of the input changes\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLInputElement>;\n /**\n * Placeholder for the input field\n */\n placeholder?: string;\n /**\n * Input type set for input element (e.g. 'text', 'number' or 'password')\n */\n type?: HTMLInputTypeAttribute;\n /**\n * Value if the input field should be controlled\n */\n value?: string;\n};\n\nconst Input: FC<InputProps> = ({\n isDisabled,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n placeholder,\n type = 'text',\n value,\n}) => {\n const [hasValue, setHasValue] = useState(typeof value === 'string' && value !== '');\n\n const handleInputFieldChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setHasValue(event.target.value !== '');\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [onChange]\n );\n\n useEffect(() => {\n if (typeof value === 'string') {\n setHasValue(value !== '');\n }\n }, [value]);\n\n const labelPosition = useMemo(() => {\n if (hasValue) {\n return { bottom: -8, right: -6 };\n }\n\n return { left: 0, top: 0 };\n }, [hasValue]);\n\n return (\n <StyledInput className=\"beta-chayns-input\" isDisabled={isDisabled}>\n <StyledInputContent>\n <StyledInputField\n disabled={isDisabled}\n onBlur={onBlur}\n onChange={handleInputFieldChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n value={value}\n type={type}\n />\n <StyledMotionInputLabel\n animate={{ scale: hasValue ? 0.6 : 1 }}\n layout\n style={{ ...labelPosition, originX: 1, originY: 1 }}\n transition={{ type: 'tween' }}\n >\n {placeholder}\n </StyledMotionInputLabel>\n </StyledInputContent>\n </StyledInput>\n );\n};\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"mappings":";;;;;;AAAA;AAYA;AAKwB;AAAA;AAq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AEC,SAAU;IACrB,KAAK,EAAEG,KAAM;IACb,IAAI,EAAED;EAAK,EACb,eACF,6BAAC,6BAAsB;IACnB,OAAO,EAAE;MAAEgB,KAAK,EAAEd,QAAQ,GAAG,GAAG,GAAG;IAAE,CAAE;IACvC,MAAM;IACN,KAAK,EAAE;MAAE,GAAGQ,aAAa;MAAEO,OAAO,EAAE,CAAC;MAAEC,OAAO,EAAE;IAAE,CAAE;IACpD,UAAU,EAAE;MAAElB,IAAI,EAAE;IAAQ;EAAE,GAE7BD,WAAW,CACS,CACR,CACX;AAEtB,CAAC;AAEDN,KAAK,CAAC0B,WAAW,GAAG,OAAO;AAAC,eAEb1B,KAAK;AAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { InputProps } from './Input';
|
|
2
|
+
export declare const StyledInput: import("styled-components").StyledComponent<"div", any, Pick<InputProps, "isDisabled"> & {
|
|
2
3
|
theme: import("../color-scheme-provider/ColorSchemeProvider").Theme;
|
|
3
4
|
}, never>;
|
|
4
5
|
export declare const StyledInputContent: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -26,7 +26,14 @@ const StyledInput = _styledComponents.default.div`
|
|
|
26
26
|
display: flex;
|
|
27
27
|
justify-content: space-between;
|
|
28
28
|
min-height: 42px;
|
|
29
|
+
opacity: ${_ref3 => {
|
|
30
|
+
let {
|
|
31
|
+
isDisabled
|
|
32
|
+
} = _ref3;
|
|
33
|
+
return isDisabled ? 0.5 : 1;
|
|
34
|
+
}};
|
|
29
35
|
padding: 8px 10px;
|
|
36
|
+
transition: opacity 0.3s ease;
|
|
30
37
|
|
|
31
38
|
&:not(&:first-child) {
|
|
32
39
|
margin-top: 8px;
|
|
@@ -38,15 +45,16 @@ const StyledInputContent = _styledComponents.default.div`
|
|
|
38
45
|
flex: 1 1 auto;
|
|
39
46
|
flex-direction: column;
|
|
40
47
|
position: relative;
|
|
48
|
+
min-width: 0;
|
|
41
49
|
`;
|
|
42
50
|
exports.StyledInputContent = StyledInputContent;
|
|
43
51
|
const StyledInputField = _styledComponents.default.input`
|
|
44
52
|
background: none;
|
|
45
53
|
border: none;
|
|
46
|
-
color: ${
|
|
54
|
+
color: ${_ref4 => {
|
|
47
55
|
let {
|
|
48
56
|
theme
|
|
49
|
-
} =
|
|
57
|
+
} = _ref4;
|
|
50
58
|
return theme.text;
|
|
51
59
|
}};
|
|
52
60
|
padding: 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.styles.js","names":["StyledInput","styled","div","theme","StyledInputContent","StyledInputField","input","text","StyledMotionInputLabel","motion","label"],"sources":["../../../src/components/input/Input.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledInputProps = WithTheme<
|
|
1
|
+
{"version":3,"file":"Input.styles.js","names":["StyledInput","styled","div","theme","isDisabled","StyledInputContent","StyledInputField","input","text","StyledMotionInputLabel","motion","label"],"sources":["../../../src/components/input/Input.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport type { InputProps } from './Input';\n\ntype StyledInputProps = WithTheme<Pick<InputProps, 'isDisabled'>>;\n\nexport const StyledInput = styled.div<StyledInputProps>`\n align-items: center;\n background-color: ${({ theme }: StyledInputProps) => theme['100']};\n border: 1px solid rgba(160, 160, 160, 0.3);\n border-radius: 3px;\n color: ${({ theme }: StyledInputProps) => theme['006']};\n display: flex;\n justify-content: space-between;\n min-height: 42px;\n opacity: ${({ isDisabled }) => (isDisabled ? 0.5 : 1)};\n padding: 8px 10px;\n transition: opacity 0.3s ease;\n\n &:not(&:first-child) {\n margin-top: 8px;\n }\n`;\n\nexport const StyledInputContent = styled.div`\n display: flex;\n flex: 1 1 auto;\n flex-direction: column;\n position: relative;\n min-width: 0;\n`;\n\nexport const StyledInputField = styled.input`\n background: none;\n border: none;\n color: ${({ theme }: StyledInputProps) => theme.text};\n padding: 0;\n`;\n\nexport const StyledMotionInputLabel = styled(motion.label)`\n line-height: 1.15;\n pointer-events: none;\n position: absolute;\n user-select: none;\n`;\n"],"mappings":";;;;;;AAAA;AACA;AAAuC;AAMhC,MAAMA,WAAW,GAAGC,yBAAM,CAACC,GAAsB;AACxD;AACA,wBAAwB;EAAA,IAAC;IAAEC;EAAwB,CAAC;EAAA,OAAKA,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AACtE;AACA;AACA,aAAa;EAAA,IAAC;IAAEA;EAAwB,CAAC;EAAA,OAAKA,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AAC3D;AACA;AACA;AACA,eAAe;EAAA,IAAC;IAAEC;EAAW,CAAC;EAAA,OAAMA,UAAU,GAAG,GAAG,GAAG,CAAC;AAAA,CAAE;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAAC;AAEK,MAAMC,kBAAkB,GAAGJ,yBAAM,CAACC,GAAI;AAC7C;AACA;AACA;AACA;AACA;AACA,CAAC;AAAC;AAEK,MAAMI,gBAAgB,GAAGL,yBAAM,CAACM,KAAM;AAC7C;AACA;AACA,aAAa;EAAA,IAAC;IAAEJ;EAAwB,CAAC;EAAA,OAAKA,KAAK,CAACK,IAAI;AAAA,CAAC;AACzD;AACA,CAAC;AAAC;AAEK,MAAMC,sBAAsB,GAAG,IAAAR,yBAAM,EAACS,oBAAM,CAACC,KAAK,CAAE;AAC3D;AACA;AACA;AACA;AACA,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.43",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "d02a5e87394dd6723b8694f37c42bd6f26dcb21f"
|
|
66
66
|
}
|