@veracity/vui 1.8.0 → 1.8.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.
@@ -1 +1 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/input/input.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA+B,YAAY,EAAE,MAAM,SAAS,CAAA;AAMnE,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,UAAU,MAAM,cAAc,CAAA;AAErC,eAAO,MAAM,SAAS,+HAiBrB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK;UAwHV,gBAAgB;WACf,iBAAiB;cACd,eAAe;CAC1B,CAAA;AAMD,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/input/input.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA+B,YAAY,EAAE,MAAM,SAAS,CAAA;AAMnE,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,UAAU,MAAM,cAAc,CAAA;AAErC,eAAO,MAAM,SAAS,+HAiBrB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK;UA+HV,gBAAgB;WACf,iBAAiB;cACd,eAAe;CAC1B,CAAA;AAMD,eAAe,KAAK,CAAA"}
@@ -73,15 +73,17 @@ exports.InputBase = core_1.styled.divBox `
73
73
  */
74
74
  exports.Input = (0, core_1.vui)((props, ref) => {
75
75
  var _a, _b, _c, _d;
76
- const [count, setCount] = (0, react_1.useState)((0, helpers_1.getInitialCount)(props));
77
76
  const { autoComplete, autoFocus, children, className, colorScheme, defaultValue, disabled, errorText, iconLeft, iconRight, id, input, inputProps, inputRef, isInvalid, itemLeft, itemRight, helpText, max, maxLength, min, name, onBlur, onChange: onChangeProp, onFocus, pattern, placeholder, readOnly, required, showCount, size, state = '', stateMapping, step, type = 'text', value, variant } = props, rest = __rest(props, ["autoComplete", "autoFocus", "children", "className", "colorScheme", "defaultValue", "disabled", "errorText", "iconLeft", "iconRight", "id", "input", "inputProps", "inputRef", "isInvalid", "itemLeft", "itemRight", "helpText", "max", "maxLength", "min", "name", "onBlur", "onChange", "onFocus", "pattern", "placeholder", "readOnly", "required", "showCount", "size", "state", "stateMapping", "step", "type", "value", "variant"]);
77
+ const [count, setCount] = (0, react_1.useState)((0, helpers_1.getInitialCount)(props));
78
+ const [valueInternal, setValueInternal] = (0, react_1.useState)(defaultValue);
78
79
  const states = Object.assign(Object.assign({}, consts_1.inputStateMapping), stateMapping);
79
80
  const computedColorScheme = (0, utils_1.filterUndefined)({
80
- colorScheme: (_a = colorScheme !== null && colorScheme !== void 0 ? colorScheme : (isInvalid ? 'red' : undefined)) !== null && _a !== void 0 ? _a : (_b = states[state]) === null || _b === void 0 ? void 0 : _b.colorScheme
81
+ colorScheme: (_a = colorScheme !== null && colorScheme !== void 0 ? colorScheme : (isInvalid ? consts_1.redColor : undefined)) !== null && _a !== void 0 ? _a : (_b = states[state]) === null || _b === void 0 ? void 0 : _b.colorScheme
81
82
  });
82
83
  const styles = (0, core_1.useStyleConfig)('Input', Object.assign(Object.assign({}, computedColorScheme), props));
83
84
  const context = (0, react_1.useMemo)(() => (0, utils_1.filterUndefined)({ colorScheme, disabled, size, variant }), [colorScheme, disabled, size, variant]);
84
85
  function onChange(e) {
86
+ setValueInternal(e.target.value);
85
87
  setCount(e.target.value.length);
86
88
  onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(e);
87
89
  }
@@ -91,6 +93,11 @@ exports.Input = (0, core_1.vui)((props, ref) => {
91
93
  focusWithinBorderColor: !readOnly ? 'transparent' : undefined,
92
94
  focusWithinRingColor: readOnly ? 'transparent' : undefined
93
95
  });
96
+ (0, react_1.useEffect)(() => {
97
+ var _a;
98
+ setValueInternal(value);
99
+ setCount(((_a = `${value}`) === null || _a === void 0 ? void 0 : _a.length) ? `${value}`.length : 0);
100
+ }, [value]);
94
101
  return (react_1.default.createElement(context_1.InputProvider, { value: context },
95
102
  react_1.default.createElement(exports.InputBase, Object.assign({ className: (0, utils_1.cs)('vui-input', className), ref: ref }, styles.container, aliasedProps, rest),
96
103
  itemLeft,
@@ -112,16 +119,15 @@ exports.Input = (0, core_1.vui)((props, ref) => {
112
119
  readOnly,
113
120
  required,
114
121
  step,
115
- type,
116
- value
117
- }, inputProps))),
122
+ type
123
+ }, { value: valueInternal }, inputProps))),
118
124
  (0, utils_1.isString)(iconRight) ? react_1.default.createElement(inputIcon_1.default, { mr: 1, name: iconRight }) : iconRight,
119
125
  itemRight,
120
126
  state && react_1.default.createElement(inputIcon_1.default, Object.assign({ mr: 1 }, (_d = states[state]) === null || _d === void 0 ? void 0 : _d.iconProps)),
121
- showCount && (react_1.default.createElement(t_1.T, { className: "vui-inputCount", color: consts_1.greyColor, position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
127
+ showCount && (react_1.default.createElement(t_1.T, { className: "vui-inputCount", color: maxLength && count > maxLength ? consts_1.redColor : consts_1.greyColor, position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
122
128
  count,
123
- " / ",
124
- maxLength))),
129
+ " ",
130
+ maxLength ? `/ ${maxLength}` : null))),
125
131
  !!helpText && react_1.default.createElement(helpText_1.default, null, helpText),
126
132
  !!errorText && react_1.default.createElement(helpText_1.default, { isError: true }, errorText)));
127
133
  });
@@ -0,0 +1,4 @@
1
+ export declare const greyLightColor = "grey.10";
2
+ export declare const greyColor = "grey.80";
3
+ export declare const redColor = "red.80";
4
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/textarea/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,YAAY,CAAA;AACvC,eAAO,MAAM,SAAS,YAAY,CAAA;AAClC,eAAO,MAAM,QAAQ,WAAW,CAAA"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redColor = exports.greyColor = exports.greyLightColor = void 0;
4
+ exports.greyLightColor = 'grey.10';
5
+ exports.greyColor = 'grey.80';
6
+ exports.redColor = 'red.80';
@@ -1 +1 @@
1
- {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../../src/textarea/textarea.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAwBhD,eAAO,MAAM,YAAY,+HAKxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,sDAmFnB,CAAA;AAEF,eAAe,QAAQ,CAAA"}
1
+ {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../../src/textarea/textarea.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAwBhD,eAAO,MAAM,YAAY,+HAKxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,sDAmGnB,CAAA;AAEF,eAAe,QAAQ,CAAA"}
@@ -42,6 +42,7 @@ const react_1 = __importStar(require("react"));
42
42
  const core_1 = require("../core");
43
43
  const t_1 = __importDefault(require("../t"));
44
44
  const utils_1 = require("../utils");
45
+ const consts_1 = require("./consts");
45
46
  const helpers_1 = require("./helpers");
46
47
  const TextareaTextarea = core_1.styled.textareaBox `
47
48
  border-radius: md;
@@ -75,13 +76,15 @@ exports.TextareaBase = core_1.styled.divBox `
75
76
  * Forwards many relevant props to the inner textarea. Exposes some props to the children via context.
76
77
  */
77
78
  exports.Textarea = (0, core_1.vui)((props, ref) => {
78
- const [count, setCount] = (0, react_1.useState)((0, helpers_1.getInitialCount)(props));
79
79
  const _a = (0, core_1.omitThemingProps)(props), { autoFocus, className, colorScheme: colorSchemeProp, cols, defaultValue, disabled, id, isInvalid, maxLength, name, onBlur, onChange: onChangeProp, onFocus, placeholder, readOnly, required, resize = 'none', rows, showCount, textareaProps = {}, textareaRef, value } = _a, rest = __rest(_a, ["autoFocus", "className", "colorScheme", "cols", "defaultValue", "disabled", "id", "isInvalid", "maxLength", "name", "onBlur", "onChange", "onFocus", "placeholder", "readOnly", "required", "resize", "rows", "showCount", "textareaProps", "textareaRef", "value"]);
80
+ const [count, setCount] = (0, react_1.useState)((0, helpers_1.getInitialCount)(props));
81
+ const [valueInternal, setValueInternal] = (0, react_1.useState)(defaultValue);
80
82
  const colorProps = (0, utils_1.filterUndefined)({
81
83
  colorScheme: colorSchemeProp !== null && colorSchemeProp !== void 0 ? colorSchemeProp : (isInvalid ? 'red' : undefined)
82
84
  });
83
85
  const styles = (0, core_1.useStyleConfig)('Textarea', Object.assign(Object.assign({}, colorProps), props));
84
86
  function onChange(e) {
87
+ setValueInternal(e.target.value);
85
88
  setCount(e.target.value.length);
86
89
  onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(e);
87
90
  }
@@ -90,10 +93,15 @@ exports.Textarea = (0, core_1.vui)((props, ref) => {
90
93
  });
91
94
  const textareaAliasedProps = (0, utils_1.filterUndefined)({
92
95
  'aria-disabled': disabled,
93
- bg: readOnly ? 'grey.20' : undefined,
96
+ bg: readOnly ? consts_1.greyLightColor : undefined,
94
97
  focusBorderColor: !readOnly ? 'transparent' : undefined,
95
98
  focusRing: readOnly ? 0 : undefined
96
99
  });
100
+ (0, react_1.useEffect)(() => {
101
+ var _a;
102
+ setValueInternal(value);
103
+ setCount(((_a = `${value}`) === null || _a === void 0 ? void 0 : _a.length) ? `${value}`.length : 0);
104
+ }, [value]);
97
105
  return (react_1.default.createElement(exports.TextareaBase, Object.assign({ className: (0, utils_1.cs)('vui-textarea', className), ref: ref }, styles.container, aliasedProps, rest),
98
106
  react_1.default.createElement(TextareaTextarea, Object.assign({ className: "vui-textareaTextarea", ref: textareaRef }, {
99
107
  autoFocus,
@@ -110,12 +118,11 @@ exports.Textarea = (0, core_1.vui)((props, ref) => {
110
118
  readOnly,
111
119
  required,
112
120
  resize,
113
- rows,
114
- value
115
- }, styles.textarea, textareaAliasedProps, textareaProps)),
116
- showCount && (react_1.default.createElement(t_1.default, { className: "vui-textareaCount", color: "grey.80", position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
121
+ rows
122
+ }, { value: valueInternal }, styles.textarea, textareaAliasedProps, textareaProps)),
123
+ showCount && (react_1.default.createElement(t_1.default, { className: "vui-textareaCount", color: maxLength && count > maxLength ? consts_1.redColor : consts_1.greyColor, position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
117
124
  count,
118
- " / ",
119
- maxLength))));
125
+ " ",
126
+ maxLength ? `/ ${maxLength}` : null))));
120
127
  });
121
128
  exports.default = exports.Textarea;
@@ -1 +1 @@
1
- {"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,YAAY,MAAM,CAAA;;AAyB/B,wBAAkC"}
1
+ {"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,YAAY,MAAM,CAAA;;AA8B/B,wBAAkC"}
@@ -10,8 +10,11 @@ const core_1 = require("../core");
10
10
  const theme_1 = require("../theme");
11
11
  exports.toasterWidth = 420;
12
12
  const Toaster = () => {
13
- var _a, _b;
13
+ var _a, _b, _c;
14
14
  const { toasts } = (0, core_1.useVuiContext)();
15
- return (react_1.default.createElement(box_1.Box, { bottom: "1rem", display: "block", maxW: { md: exports.toasterWidth, sm: exports.toasterWidth, xs: '100%' }, minW: { md: exports.toasterWidth, sm: exports.toasterWidth, xs: '100%' }, p: { md: '16px', sm: '4px', xs: '2px' }, position: "fixed", right: { md: '1rem', sm: 0, xs: 0 }, zIndex: theme_1.zIndices.toast }, (_b = (_a = toasts === null || toasts === void 0 ? void 0 : toasts.list) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (toast) => (react_1.default.createElement("div", { id: `toast_${toast.id}`, key: toast.id }, toast.component)))));
15
+ const padding = ((_a = toasts === null || toasts === void 0 ? void 0 : toasts.list) === null || _a === void 0 ? void 0 : _a.length) ? { md: '16px', sm: '4px', xs: '2px' } : 0;
16
+ const right = { md: '1rem', sm: 0, xs: 0 };
17
+ const width = { md: exports.toasterWidth, sm: exports.toasterWidth, xs: '100%' };
18
+ return (react_1.default.createElement(box_1.Box, { bottom: "1rem", className: "vui-toaster", display: "block", maxW: width, minW: width, p: padding, position: "fixed", right: right, zIndex: theme_1.zIndices.toast }, (_c = (_b = toasts === null || toasts === void 0 ? void 0 : toasts.list) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.call(_b, (toast) => (react_1.default.createElement(core_1.v.div, { id: `toast_${toast.id}`, key: toast.id }, toast.component)))));
16
19
  };
17
20
  exports.default = react_1.default.memo(Toaster);
@@ -1 +1 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/input/input.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA+B,YAAY,EAAE,MAAM,SAAS,CAAA;AAMnE,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,UAAU,MAAM,cAAc,CAAA;AAErC,eAAO,MAAM,SAAS,+HAiBrB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK;UAwHV,gBAAgB;WACf,iBAAiB;cACd,eAAe;CAC1B,CAAA;AAMD,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/input/input.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA+B,YAAY,EAAE,MAAM,SAAS,CAAA;AAMnE,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,UAAU,MAAM,cAAc,CAAA;AAErC,eAAO,MAAM,SAAS,+HAiBrB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK;UA+HV,gBAAgB;WACf,iBAAiB;cACd,eAAe;CAC1B,CAAA;AAMD,eAAe,KAAK,CAAA"}
@@ -1,8 +1,8 @@
1
- import React, { useMemo, useState } from 'react';
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
2
  import { styled, useStyleConfig, vui } from '../core';
3
3
  import { T } from '../t';
4
4
  import { cs, filterUndefined, isString } from '../utils';
5
- import { greyColor, greyLightColor, inputStateMapping } from './consts';
5
+ import { greyColor, greyLightColor, inputStateMapping, redColor } from './consts';
6
6
  import { InputProvider } from './context';
7
7
  import { getInitialCount } from './helpers';
8
8
  import HelpText from './helpText';
@@ -32,15 +32,17 @@ export const InputBase = styled.divBox `
32
32
  * Exposes some props to the children via context.
33
33
  */
34
34
  export const Input = vui((props, ref) => {
35
- const [count, setCount] = useState(getInitialCount(props));
36
35
  const { autoComplete, autoFocus, children, className, colorScheme, defaultValue, disabled, errorText, iconLeft, iconRight, id, input, inputProps, inputRef, isInvalid, itemLeft, itemRight, helpText, max, maxLength, min, name, onBlur, onChange: onChangeProp, onFocus, pattern, placeholder, readOnly, required, showCount, size, state = '', stateMapping, step, type = 'text', value, variant, ...rest } = props;
36
+ const [count, setCount] = useState(getInitialCount(props));
37
+ const [valueInternal, setValueInternal] = useState(defaultValue);
37
38
  const states = { ...inputStateMapping, ...stateMapping };
38
39
  const computedColorScheme = filterUndefined({
39
- colorScheme: colorScheme ?? (isInvalid ? 'red' : undefined) ?? states[state]?.colorScheme
40
+ colorScheme: colorScheme ?? (isInvalid ? redColor : undefined) ?? states[state]?.colorScheme
40
41
  });
41
42
  const styles = useStyleConfig('Input', { ...computedColorScheme, ...props });
42
43
  const context = useMemo(() => filterUndefined({ colorScheme, disabled, size, variant }), [colorScheme, disabled, size, variant]);
43
44
  function onChange(e) {
45
+ setValueInternal(e.target.value);
44
46
  setCount(e.target.value.length);
45
47
  onChangeProp?.(e);
46
48
  }
@@ -50,6 +52,10 @@ export const Input = vui((props, ref) => {
50
52
  focusWithinBorderColor: !readOnly ? 'transparent' : undefined,
51
53
  focusWithinRingColor: readOnly ? 'transparent' : undefined
52
54
  });
55
+ useEffect(() => {
56
+ setValueInternal(value);
57
+ setCount(`${value}`?.length ? `${value}`.length : 0);
58
+ }, [value]);
53
59
  return (React.createElement(InputProvider, { value: context },
54
60
  React.createElement(InputBase, { className: cs('vui-input', className), ref: ref, ...styles.container, ...aliasedProps, ...rest },
55
61
  itemLeft,
@@ -72,16 +78,15 @@ export const Input = vui((props, ref) => {
72
78
  readOnly,
73
79
  required,
74
80
  step,
75
- type,
76
- value
77
- }, ...inputProps })),
81
+ type
82
+ }, value: valueInternal, ...inputProps })),
78
83
  isString(iconRight) ? React.createElement(InputIcon, { mr: 1, name: iconRight }) : iconRight,
79
84
  itemRight,
80
85
  state && React.createElement(InputIcon, { mr: 1, ...states[state]?.iconProps }),
81
- showCount && (React.createElement(T, { className: "vui-inputCount", color: greyColor, position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
86
+ showCount && (React.createElement(T, { className: "vui-inputCount", color: maxLength && count > maxLength ? redColor : greyColor, position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
82
87
  count,
83
- " / ",
84
- maxLength))),
88
+ " ",
89
+ maxLength ? `/ ${maxLength}` : null))),
85
90
  !!helpText && React.createElement(HelpText, null, helpText),
86
91
  !!errorText && React.createElement(HelpText, { isError: true }, errorText)));
87
92
  });
@@ -0,0 +1,4 @@
1
+ export declare const greyLightColor = "grey.10";
2
+ export declare const greyColor = "grey.80";
3
+ export declare const redColor = "red.80";
4
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/textarea/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,YAAY,CAAA;AACvC,eAAO,MAAM,SAAS,YAAY,CAAA;AAClC,eAAO,MAAM,QAAQ,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ export const greyLightColor = 'grey.10';
2
+ export const greyColor = 'grey.80';
3
+ export const redColor = 'red.80';
@@ -1 +1 @@
1
- {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../../src/textarea/textarea.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAwBhD,eAAO,MAAM,YAAY,+HAKxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,sDAmFnB,CAAA;AAEF,eAAe,QAAQ,CAAA"}
1
+ {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../../src/textarea/textarea.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAwBhD,eAAO,MAAM,YAAY,+HAKxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,sDAmGnB,CAAA;AAEF,eAAe,QAAQ,CAAA"}
@@ -1,7 +1,8 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import { omitThemingProps, styled, useStyleConfig, vui } from '../core';
3
3
  import T from '../t';
4
4
  import { cs, filterUndefined } from '../utils';
5
+ import { greyColor, greyLightColor, redColor } from './consts';
5
6
  import { getInitialCount } from './helpers';
6
7
  const TextareaTextarea = styled.textareaBox `
7
8
  border-radius: md;
@@ -35,13 +36,15 @@ export const TextareaBase = styled.divBox `
35
36
  * Forwards many relevant props to the inner textarea. Exposes some props to the children via context.
36
37
  */
37
38
  export const Textarea = vui((props, ref) => {
38
- const [count, setCount] = useState(getInitialCount(props));
39
39
  const { autoFocus, className, colorScheme: colorSchemeProp, cols, defaultValue, disabled, id, isInvalid, maxLength, name, onBlur, onChange: onChangeProp, onFocus, placeholder, readOnly, required, resize = 'none', rows, showCount, textareaProps = {}, textareaRef, value, ...rest } = omitThemingProps(props);
40
+ const [count, setCount] = useState(getInitialCount(props));
41
+ const [valueInternal, setValueInternal] = useState(defaultValue);
40
42
  const colorProps = filterUndefined({
41
43
  colorScheme: colorSchemeProp ?? (isInvalid ? 'red' : undefined)
42
44
  });
43
45
  const styles = useStyleConfig('Textarea', { ...colorProps, ...props });
44
46
  function onChange(e) {
47
+ setValueInternal(e.target.value);
45
48
  setCount(e.target.value.length);
46
49
  onChangeProp?.(e);
47
50
  }
@@ -50,10 +53,14 @@ export const Textarea = vui((props, ref) => {
50
53
  });
51
54
  const textareaAliasedProps = filterUndefined({
52
55
  'aria-disabled': disabled,
53
- bg: readOnly ? 'grey.20' : undefined,
56
+ bg: readOnly ? greyLightColor : undefined,
54
57
  focusBorderColor: !readOnly ? 'transparent' : undefined,
55
58
  focusRing: readOnly ? 0 : undefined
56
59
  });
60
+ useEffect(() => {
61
+ setValueInternal(value);
62
+ setCount(`${value}`?.length ? `${value}`.length : 0);
63
+ }, [value]);
57
64
  return (React.createElement(TextareaBase, { className: cs('vui-textarea', className), ref: ref, ...styles.container, ...aliasedProps, ...rest },
58
65
  React.createElement(TextareaTextarea, { className: "vui-textareaTextarea", ref: textareaRef, ...{
59
66
  autoFocus,
@@ -70,12 +77,11 @@ export const Textarea = vui((props, ref) => {
70
77
  readOnly,
71
78
  required,
72
79
  resize,
73
- rows,
74
- value
75
- }, ...styles.textarea, ...textareaAliasedProps, ...textareaProps }),
76
- showCount && (React.createElement(T, { className: "vui-textareaCount", color: "grey.80", position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
80
+ rows
81
+ }, value: valueInternal, ...styles.textarea, ...textareaAliasedProps, ...textareaProps }),
82
+ showCount && (React.createElement(T, { className: "vui-textareaCount", color: maxLength && count > maxLength ? redColor : greyColor, position: "absolute", right: 0, size: "sm", top: "calc(100% + 1px)" },
77
83
  count,
78
- " / ",
79
- maxLength))));
84
+ " ",
85
+ maxLength ? `/ ${maxLength}` : null))));
80
86
  });
81
87
  export default Textarea;
@@ -1 +1 @@
1
- {"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,YAAY,MAAM,CAAA;;AAyB/B,wBAAkC"}
1
+ {"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../../src/toast/toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,YAAY,MAAM,CAAA;;AA8B/B,wBAAkC"}
@@ -1,10 +1,13 @@
1
1
  import React from 'react';
2
2
  import { Box } from '../box';
3
- import { useVuiContext } from '../core';
3
+ import { useVuiContext, v } from '../core';
4
4
  import { zIndices } from '../theme';
5
5
  export const toasterWidth = 420;
6
6
  const Toaster = () => {
7
7
  const { toasts } = useVuiContext();
8
- return (React.createElement(Box, { bottom: "1rem", display: "block", maxW: { md: toasterWidth, sm: toasterWidth, xs: '100%' }, minW: { md: toasterWidth, sm: toasterWidth, xs: '100%' }, p: { md: '16px', sm: '4px', xs: '2px' }, position: "fixed", right: { md: '1rem', sm: 0, xs: 0 }, zIndex: zIndices.toast }, toasts?.list?.map?.((toast) => (React.createElement("div", { id: `toast_${toast.id}`, key: toast.id }, toast.component)))));
8
+ const padding = toasts?.list?.length ? { md: '16px', sm: '4px', xs: '2px' } : 0;
9
+ const right = { md: '1rem', sm: 0, xs: 0 };
10
+ const width = { md: toasterWidth, sm: toasterWidth, xs: '100%' };
11
+ return (React.createElement(Box, { bottom: "1rem", className: "vui-toaster", display: "block", maxW: width, minW: width, p: padding, position: "fixed", right: right, zIndex: zIndices.toast }, toasts?.list?.map?.((toast) => (React.createElement(v.div, { id: `toast_${toast.id}`, key: toast.id }, toast.component)))));
9
12
  };
10
13
  export default React.memo(Toaster);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veracity/vui",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.",
5
5
  "module": "./dist/esm/index.js",
6
6
  "main": "./dist/cjs/index.js",
@@ -1,9 +1,9 @@
1
- import React, { useMemo, useState } from 'react'
1
+ import React, { useEffect, useMemo, useState } from 'react'
2
2
 
3
3
  import { styled, useStyleConfig, vui, VuiComponent } from '../core'
4
4
  import { T } from '../t'
5
5
  import { ChangeEvent, cs, filterUndefined, isString } from '../utils'
6
- import { greyColor, greyLightColor, inputStateMapping } from './consts'
6
+ import { greyColor, greyLightColor, inputStateMapping, redColor } from './consts'
7
7
  import { InputProvider } from './context'
8
8
  import { getInitialCount } from './helpers'
9
9
  import HelpText from './helpText'
@@ -36,7 +36,6 @@ export const InputBase = styled.divBox`
36
36
  * Exposes some props to the children via context.
37
37
  */
38
38
  export const Input = vui<'div', InputProps>((props, ref) => {
39
- const [count, setCount] = useState(getInitialCount(props))
40
39
  const {
41
40
  autoComplete,
42
41
  autoFocus,
@@ -78,9 +77,11 @@ export const Input = vui<'div', InputProps>((props, ref) => {
78
77
  ...rest
79
78
  } = props
80
79
 
80
+ const [count, setCount] = useState(getInitialCount(props))
81
+ const [valueInternal, setValueInternal] = useState(defaultValue)
81
82
  const states = { ...inputStateMapping, ...stateMapping }
82
83
  const computedColorScheme = filterUndefined({
83
- colorScheme: colorScheme ?? (isInvalid ? 'red' : undefined) ?? states[state]?.colorScheme
84
+ colorScheme: colorScheme ?? (isInvalid ? redColor : undefined) ?? states[state]?.colorScheme
84
85
  })
85
86
 
86
87
  const styles = useStyleConfig('Input', { ...computedColorScheme, ...props })
@@ -91,6 +92,7 @@ export const Input = vui<'div', InputProps>((props, ref) => {
91
92
  )
92
93
 
93
94
  function onChange(e: ChangeEvent) {
95
+ setValueInternal(e.target.value)
94
96
  setCount(e.target.value.length)
95
97
  onChangeProp?.(e)
96
98
  }
@@ -102,6 +104,11 @@ export const Input = vui<'div', InputProps>((props, ref) => {
102
104
  focusWithinRingColor: readOnly ? 'transparent' : undefined
103
105
  })
104
106
 
107
+ useEffect(() => {
108
+ setValueInternal(value)
109
+ setCount(`${value}`?.length ? `${value}`.length : 0)
110
+ }, [value])
111
+
105
112
  return (
106
113
  <InputProvider value={context}>
107
114
  <InputBase className={cs('vui-input', className)} ref={ref} {...styles.container} {...aliasedProps} {...rest}>
@@ -128,9 +135,9 @@ export const Input = vui<'div', InputProps>((props, ref) => {
128
135
  readOnly,
129
136
  required,
130
137
  step,
131
- type,
132
- value
138
+ type
133
139
  }}
140
+ value={valueInternal}
134
141
  {...inputProps}
135
142
  />
136
143
  )}
@@ -140,13 +147,13 @@ export const Input = vui<'div', InputProps>((props, ref) => {
140
147
  {showCount && (
141
148
  <T
142
149
  className="vui-inputCount"
143
- color={greyColor}
150
+ color={maxLength && count > maxLength ? redColor : greyColor}
144
151
  position="absolute"
145
152
  right={0}
146
153
  size="sm"
147
154
  top="calc(100% + 1px)"
148
155
  >
149
- {count} / {maxLength}
156
+ {count} {maxLength ? `/ ${maxLength}` : null}
150
157
  </T>
151
158
  )}
152
159
  </InputBase>
@@ -0,0 +1,3 @@
1
+ export const greyLightColor = 'grey.10'
2
+ export const greyColor = 'grey.80'
3
+ export const redColor = 'red.80'
@@ -1,8 +1,9 @@
1
- import React, { useState } from 'react'
1
+ import React, { useEffect, useState } from 'react'
2
2
 
3
3
  import { omitThemingProps, styled, useStyleConfig, vui } from '../core'
4
4
  import T from '../t'
5
5
  import { ChangeEvent, cs, filterUndefined } from '../utils'
6
+ import { greyColor, greyLightColor, redColor } from './consts'
6
7
  import { getInitialCount } from './helpers'
7
8
  import { TextareaProps } from './textarea.types'
8
9
 
@@ -40,7 +41,6 @@ export const TextareaBase = styled.divBox`
40
41
  * Forwards many relevant props to the inner textarea. Exposes some props to the children via context.
41
42
  */
42
43
  export const Textarea = vui<'div', TextareaProps>((props, ref) => {
43
- const [count, setCount] = useState(getInitialCount(props))
44
44
  const {
45
45
  autoFocus,
46
46
  className,
@@ -66,12 +66,17 @@ export const Textarea = vui<'div', TextareaProps>((props, ref) => {
66
66
  value,
67
67
  ...rest
68
68
  } = omitThemingProps(props)
69
+
70
+ const [count, setCount] = useState(getInitialCount(props))
71
+ const [valueInternal, setValueInternal] = useState(defaultValue)
72
+
69
73
  const colorProps = filterUndefined({
70
74
  colorScheme: colorSchemeProp ?? (isInvalid ? 'red' : undefined)
71
75
  })
72
76
  const styles = useStyleConfig('Textarea', { ...colorProps, ...props })
73
77
 
74
78
  function onChange(e: ChangeEvent<HTMLTextAreaElement>) {
79
+ setValueInternal(e.target.value)
75
80
  setCount(e.target.value.length)
76
81
  onChangeProp?.(e)
77
82
  }
@@ -82,11 +87,16 @@ export const Textarea = vui<'div', TextareaProps>((props, ref) => {
82
87
 
83
88
  const textareaAliasedProps = filterUndefined({
84
89
  'aria-disabled': disabled,
85
- bg: readOnly ? 'grey.20' : undefined,
90
+ bg: readOnly ? greyLightColor : undefined,
86
91
  focusBorderColor: !readOnly ? 'transparent' : undefined,
87
92
  focusRing: readOnly ? 0 : undefined
88
93
  })
89
94
 
95
+ useEffect(() => {
96
+ setValueInternal(value)
97
+ setCount(`${value}`?.length ? `${value}`.length : 0)
98
+ }, [value])
99
+
90
100
  return (
91
101
  <TextareaBase className={cs('vui-textarea', className)} ref={ref} {...styles.container} {...aliasedProps} {...rest}>
92
102
  <TextareaTextarea
@@ -107,17 +117,24 @@ export const Textarea = vui<'div', TextareaProps>((props, ref) => {
107
117
  readOnly,
108
118
  required,
109
119
  resize,
110
- rows,
111
- value
120
+ rows
112
121
  }}
122
+ value={valueInternal}
113
123
  {...styles.textarea}
114
124
  {...textareaAliasedProps}
115
125
  {...textareaProps}
116
126
  />
117
127
 
118
128
  {showCount && (
119
- <T className="vui-textareaCount" color="grey.80" position="absolute" right={0} size="sm" top="calc(100% + 1px)">
120
- {count} / {maxLength}
129
+ <T
130
+ className="vui-textareaCount"
131
+ color={maxLength && count > maxLength ? redColor : greyColor}
132
+ position="absolute"
133
+ right={0}
134
+ size="sm"
135
+ top="calc(100% + 1px)"
136
+ >
137
+ {count} {maxLength ? `/ ${maxLength}` : null}
121
138
  </T>
122
139
  )}
123
140
  </TextareaBase>
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
 
3
3
  import { Box } from '../box'
4
- import { useVuiContext } from '../core'
4
+ import { useVuiContext, v } from '../core'
5
5
  import { zIndices } from '../theme'
6
6
  import { ToastListItem } from './toast.types'
7
7
 
@@ -10,21 +10,26 @@ export const toasterWidth = 420
10
10
  const Toaster = () => {
11
11
  const { toasts } = useVuiContext()
12
12
 
13
+ const padding = toasts?.list?.length ? { md: '16px', sm: '4px', xs: '2px' } : 0
14
+ const right = { md: '1rem', sm: 0, xs: 0 }
15
+ const width = { md: toasterWidth, sm: toasterWidth, xs: '100%' }
16
+
13
17
  return (
14
18
  <Box
15
19
  bottom="1rem"
20
+ className="vui-toaster"
16
21
  display="block"
17
- maxW={{ md: toasterWidth, sm: toasterWidth, xs: '100%' }}
18
- minW={{ md: toasterWidth, sm: toasterWidth, xs: '100%' }}
19
- p={{ md: '16px', sm: '4px', xs: '2px' }}
22
+ maxW={width}
23
+ minW={width}
24
+ p={padding}
20
25
  position="fixed"
21
- right={{ md: '1rem', sm: 0, xs: 0 }}
26
+ right={right}
22
27
  zIndex={zIndices.toast}
23
28
  >
24
29
  {toasts?.list?.map?.((toast: ToastListItem) => (
25
- <div id={`toast_${toast.id}`} key={toast.id}>
30
+ <v.div id={`toast_${toast.id}`} key={toast.id}>
26
31
  {toast.component}
27
- </div>
32
+ </v.div>
28
33
  ))}
29
34
  </Box>
30
35
  )