@teamturing/react-kit 2.18.0 → 2.19.0

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.
@@ -164,6 +164,6 @@ const BaseCheckbox = styled(UnstyledCheckbox)`
164
164
 
165
165
  ${sx}
166
166
  `;
167
- var index = /*#__PURE__*/forwardRef(Checkbox);
167
+ var Checkbox$1 = /*#__PURE__*/forwardRef(Checkbox);
168
168
 
169
- export { index as default };
169
+ export { Checkbox$1 as default };
@@ -0,0 +1,21 @@
1
+ import { useContext } from 'react';
2
+ import Text from '../Text/index.js';
3
+ import { FormControlContext } from './index.js';
4
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
5
+
6
+ const FormControlCaption = ({
7
+ children
8
+ }) => {
9
+ const {
10
+ id
11
+ } = useContext(FormControlContext);
12
+ return /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
13
+ as: 'span',
14
+ id: id,
15
+ typography: 'xs',
16
+ color: 'text/neutral/subtlest',
17
+ children: children
18
+ });
19
+ };
20
+
21
+ export { FormControlCaption as default };
@@ -0,0 +1,34 @@
1
+ import { useContext } from 'react';
2
+ import styled, { keyframes } from 'styled-components';
3
+ import Text from '../Text/index.js';
4
+ import { FormControlContext } from './index.js';
5
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
6
+
7
+ const FormControlErrorMessage = ({
8
+ children
9
+ }) => {
10
+ const {
11
+ id
12
+ } = useContext(FormControlContext);
13
+ return /*#__PURE__*/jsxRuntimeExports.jsx(StyledText, {
14
+ id: id,
15
+ typography: 'xs',
16
+ color: 'text/danger',
17
+ children: children
18
+ });
19
+ };
20
+ const errorMessageKeyframe = keyframes`
21
+ 0% {
22
+ opacity: 0;
23
+ transform: translateY(-100%);
24
+ }
25
+ 100% {
26
+ opacity: 1;
27
+ transform: translateY(0);
28
+ }
29
+ `;
30
+ const StyledText = styled(Text)`
31
+ animation: 170ms ${errorMessageKeyframe} cubic-bezier(0.44, 0.74, 0.36, 1);
32
+ `;
33
+
34
+ export { FormControlErrorMessage as default };
@@ -0,0 +1,79 @@
1
+ import { useContext } from 'react';
2
+ import styled from 'styled-components';
3
+ import { forcePixelValue } from '../../utils/forcePixelValue.js';
4
+ import { sx } from '../../utils/styled-system/index.js';
5
+ import View from '../View/index.js';
6
+ import { FormControlContext } from './index.js';
7
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
8
+
9
+ const FormControlLabel = ({
10
+ children,
11
+ visuallyHidden,
12
+ ...props
13
+ }) => {
14
+ const {
15
+ id,
16
+ disabled,
17
+ required
18
+ } = useContext(FormControlContext);
19
+ return /*#__PURE__*/jsxRuntimeExports.jsx(VisuallyHidden, {
20
+ as: 'label',
21
+ htmlFor: id,
22
+ isVisible: !visuallyHidden,
23
+ children: /*#__PURE__*/jsxRuntimeExports.jsxs(LabelWrapper, {
24
+ ...props,
25
+ disabled: disabled,
26
+ children: [children, required ? /*#__PURE__*/jsxRuntimeExports.jsx(View, {
27
+ as: 'span',
28
+ "aria-hidden": "true",
29
+ children: ' *'
30
+ }) : null]
31
+ })
32
+ });
33
+ };
34
+ const VisuallyHidden = styled.span`
35
+ ${({
36
+ isVisible = false
37
+ }) => {
38
+ if (isVisible) {
39
+ return sx;
40
+ }
41
+ return `
42
+ position: absolute;
43
+ width: 1px;
44
+ height: 1px;
45
+ padding: 0;
46
+ margin: -1px;
47
+ overflow: hidden;
48
+ clip: rect(0, 0, 0, 0);
49
+ white-space: nowrap;
50
+ border-width: 0;
51
+ `;
52
+ }}
53
+ `;
54
+ const LabelWrapper = styled(View)`
55
+ display: block;
56
+ align-self: flex-start;
57
+
58
+ font-size: ${({
59
+ theme
60
+ }) => forcePixelValue(theme.fontSizes.xs)};
61
+ font-weight: ${({
62
+ theme
63
+ }) => theme.fontWeights.medium};
64
+ line-height: ${({
65
+ theme
66
+ }) => theme.lineHeights[2]};
67
+
68
+ color: ${({
69
+ theme
70
+ }) => theme.colors['text/neutral/subtle']};
71
+
72
+ cursor: ${({
73
+ disabled
74
+ }) => disabled ? 'not-allowed' : 'pointer'};
75
+
76
+ ${sx};
77
+ `;
78
+
79
+ export { FormControlLabel as default };
@@ -0,0 +1,34 @@
1
+ import { useContext } from 'react';
2
+ import styled, { keyframes } from 'styled-components';
3
+ import Text from '../Text/index.js';
4
+ import { FormControlContext } from './index.js';
5
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
6
+
7
+ const FormControlSuccessMessage = ({
8
+ children
9
+ }) => {
10
+ const {
11
+ id
12
+ } = useContext(FormControlContext);
13
+ return /*#__PURE__*/jsxRuntimeExports.jsx(StyledText, {
14
+ id: id,
15
+ typography: 'xs',
16
+ color: 'text/success',
17
+ children: children
18
+ });
19
+ };
20
+ const successMessageKeyframe = keyframes`
21
+ 0% {
22
+ opacity: 0;
23
+ transform: translateY(-100%);
24
+ }
25
+ 100% {
26
+ opacity: 1;
27
+ transform: translateY(0);
28
+ }
29
+ `;
30
+ const StyledText = styled(Text)`
31
+ animation: 170ms ${successMessageKeyframe} cubic-bezier(0.44, 0.74, 0.36, 1);
32
+ `;
33
+
34
+ export { FormControlSuccessMessage as default };
@@ -0,0 +1,87 @@
1
+ import { forwardRef, createContext, isValidElement, cloneElement } from 'react';
2
+ import useRelocation from '../../hook/useRelocation.js';
3
+ import Checkbox from '../Checkbox/index.js';
4
+ import OverlaySelectInput from '../OverlaySelectInput/index.js';
5
+ import Select from '../Select/index.js';
6
+ import TextInput from '../TextInput/index.js';
7
+ import View from '../View/index.js';
8
+ import FormControlCaption from './FormControlCaption.js';
9
+ import FormControlErrorMessage from './FormControlErrorMessage.js';
10
+ import FormControlLabel from './FormControlLabel.js';
11
+ import FormControlSuccessMessage from './FormControlSuccessMessage.js';
12
+ import { j as jsxRuntimeExports } from '../../node_modules/react/jsx-runtime.js';
13
+
14
+ const FormControlContext = /*#__PURE__*/createContext({});
15
+ const FormControl = ({
16
+ children: propChildren,
17
+ id,
18
+ disabled,
19
+ required,
20
+ additionalInputComponentCandidates
21
+ }, ref) => {
22
+ const [relocatableComponentsObject, restComponents] = useRelocation({
23
+ children: propChildren,
24
+ config: {
25
+ label: FormControlLabel,
26
+ caption: FormControlCaption,
27
+ errorMessage: FormControlErrorMessage,
28
+ successMessage: FormControlSuccessMessage
29
+ }
30
+ });
31
+ const inputComponentCandidates = [TextInput, Select, OverlaySelectInput, Checkbox, ...additionalInputComponentCandidates];
32
+ const InputComponent = restComponents.find(component => inputComponentCandidates.some(candidate => /*#__PURE__*/isValidElement(component) && component.type === candidate));
33
+ const isHorizontalLayoutNeeded = /*#__PURE__*/isValidElement(InputComponent) && InputComponent.type === Checkbox;
34
+ return /*#__PURE__*/jsxRuntimeExports.jsx(FormControlContext.Provider, {
35
+ value: {
36
+ id,
37
+ disabled,
38
+ required
39
+ },
40
+ children: isHorizontalLayoutNeeded ? /*#__PURE__*/jsxRuntimeExports.jsxs(View, {
41
+ ref: ref,
42
+ display: 'flex',
43
+ sx: {
44
+ columnGap: 2
45
+ },
46
+ children: [/*#__PURE__*/jsxRuntimeExports.jsx(View, {
47
+ children: /*#__PURE__*/cloneElement(InputComponent, {
48
+ id,
49
+ disabled,
50
+ required
51
+ })
52
+ }), /*#__PURE__*/jsxRuntimeExports.jsxs(View, {
53
+ sx: {
54
+ '& > span': {
55
+ mt: 0
56
+ }
57
+ },
58
+ children: [relocatableComponentsObject.label, relocatableComponentsObject.caption, relocatableComponentsObject.errorMessage, relocatableComponentsObject.successMessage]
59
+ })]
60
+ }) : /*#__PURE__*/jsxRuntimeExports.jsxs(View, {
61
+ ref: ref,
62
+ display: 'flex',
63
+ flexDirection: 'column',
64
+ sx: {
65
+ '& > label': {
66
+ mb: 1
67
+ },
68
+ '& > span': {
69
+ mt: 1
70
+ }
71
+ },
72
+ children: [relocatableComponentsObject.label, /*#__PURE__*/cloneElement(InputComponent, {
73
+ id,
74
+ disabled,
75
+ required
76
+ }), relocatableComponentsObject.caption, relocatableComponentsObject.errorMessage, relocatableComponentsObject.successMessage]
77
+ })
78
+ });
79
+ };
80
+ var index = Object.assign( /*#__PURE__*/forwardRef(FormControl), {
81
+ Label: FormControlLabel,
82
+ Caption: FormControlCaption,
83
+ ErrorMessage: FormControlErrorMessage,
84
+ SuccessMessage: FormControlSuccessMessage
85
+ });
86
+
87
+ export { FormControlContext, index as default };
@@ -232,6 +232,6 @@ const BaseInput = styled(UnstyledInput)`
232
232
  theme
233
233
  }) => forcePixelValue(theme.space['5'])};
234
234
  `;
235
- var index = /*#__PURE__*/forwardRef(OverlaySelectInput);
235
+ var OverlaySelectInput$1 = /*#__PURE__*/forwardRef(OverlaySelectInput);
236
236
 
237
- export { index as default };
237
+ export { OverlaySelectInput$1 as default };
@@ -63,7 +63,7 @@ const Select = ({
63
63
  }
64
64
  }
65
65
  },
66
- children: [/*#__PURE__*/jsxRuntimeExports.jsx("option", {
66
+ children: [/*#__PURE__*/jsxRuntimeExports.jsx(SelectOption, {
67
67
  label: placeholder,
68
68
  value: PLACEHOLDER_VALUE
69
69
  }), children]
@@ -227,8 +227,8 @@ const BaseSelect = styled(UnstyledSelect)`
227
227
  white-space: pre;
228
228
  text-overflow: ellipsis;
229
229
  `;
230
- var index = Object.assign( /*#__PURE__*/forwardRef(Select), {
230
+ var Select$1 = Object.assign( /*#__PURE__*/forwardRef(Select), {
231
231
  Option: SelectOption
232
232
  });
233
233
 
234
- export { index as default };
234
+ export { Select$1 as default };
@@ -225,8 +225,8 @@ const BaseInput = styled(UnstyledInput)`
225
225
  theme
226
226
  }) => forcePixelValue(theme.space['5'])};
227
227
  `;
228
- var index = Object.assign( /*#__PURE__*/forwardRef(TextInput), {
228
+ var TextInput$1 = Object.assign( /*#__PURE__*/forwardRef(TextInput), {
229
229
  TrailingAction: TextInputTrailingAction
230
230
  });
231
231
 
232
- export { index as default };
232
+ export { TextInput$1 as default };
package/esm/index.js CHANGED
@@ -9,6 +9,7 @@ export { default as DescriptionList } from './core/DescriptionList/index.js';
9
9
  export { default as Dialog } from './core/Dialog/index.js';
10
10
  export { default as DialogHandler } from './core/DialogHandler/index.js';
11
11
  export { default as EmptyState } from './core/EmptyState/index.js';
12
+ export { default as FormControl } from './core/FormControl/index.js';
12
13
  export { default as GradientText } from './core/GradientText/index.js';
13
14
  export { default as Grid } from './core/Grid/index.js';
14
15
  export { default as HorizontalDivider } from './core/HorizontalDivider/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamturing/react-kit",
3
- "version": "2.18.0",
3
+ "version": "2.19.0",
4
4
  "description": "React components, hooks for create teamturing web application",
5
5
  "author": "Sungchang Park <psch300@gmail.com> (https://github.com/psch300)",
6
6
  "homepage": "https://github.com/weareteamturing/bombe#readme",
@@ -62,5 +62,5 @@
62
62
  "react-is": "^18.2.0",
63
63
  "styled-system": "^5.1.5"
64
64
  },
65
- "gitHead": "7e5d700d947efa6123f50698bdcef68160fb21e3"
65
+ "gitHead": "0a40eab032d58877e2176890d7ea32f758366e26"
66
66
  }