ish-ui 1.3.9 → 1.4.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.
|
@@ -108,54 +108,55 @@ const useStyles = makeAppStyles()(({ spacing, palette, zIndex, transitions }, p,
|
|
|
108
108
|
}));
|
|
109
109
|
// Gap between the anchor and the paper, leaving room for the arrow.
|
|
110
110
|
const popperModifiers = [{ name: 'offset', options: { offset: [0, 12] } }];
|
|
111
|
-
const ColorPickerBase = React.memo(({ color, input: {
|
|
111
|
+
const ColorPickerBase = React.memo(({ color, input: { onChange }, TransitionProps, setAnchorEl }) => {
|
|
112
112
|
const { classes } = useStyles();
|
|
113
|
-
|
|
114
|
-
const [
|
|
113
|
+
// Single source of truth for all pickers; null until HuePicker has parsed the initial color
|
|
114
|
+
const [hsv, setHsv] = useState(null);
|
|
115
115
|
const hueRef = useRef(undefined);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
// Alpha slider is used as a saturation slider, so saturation is passed as alpha
|
|
117
|
+
const hueColor = useMemo(() => (hsv ? Object.assign(Object.assign({}, hsv), { a: 1 }) : color), [hsv, color]);
|
|
118
|
+
const alfaColor = useMemo(() => (hsv ? {
|
|
119
|
+
h: hsv.h, s: 1, v: hsv.v, a: hsv.s
|
|
120
|
+
} : color), [hsv, color]);
|
|
121
|
+
const onHueChange = useCallback(color => {
|
|
122
|
+
setHsv(prev => (Object.assign(Object.assign({}, (prev || color.hsv)), { h: color.hsv.h })));
|
|
121
123
|
}, []);
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
const onAlfaChange = useCallback(color => {
|
|
125
|
+
setHsv(prev => (Object.assign(Object.assign({}, (prev || color.hsv)), { s: color.hsv.a })));
|
|
126
|
+
}, []);
|
|
127
|
+
const onMaterialChange = useCallback(color => {
|
|
128
|
+
setHsv({ h: color.hsv.h, s: color.hsv.s, v: color.hsv.v });
|
|
129
|
+
}, []);
|
|
130
|
+
const commitHex = (hex) => {
|
|
125
131
|
if (hex) {
|
|
126
132
|
onChange(hex.replace('#', ''));
|
|
127
133
|
}
|
|
128
134
|
};
|
|
135
|
+
// Slider pickers report their own (saturation-substituted) color, so take the resulting one from HuePicker
|
|
136
|
+
const onSliderChangeComplete = () => { var _a, _b; return commitHex((_b = (_a = hueRef.current) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.hex); };
|
|
137
|
+
const onMaterialChangeComplete = color => commitHex(color.hex);
|
|
129
138
|
const handleClickAway = useCallback(() => {
|
|
130
139
|
setAnchorEl(null);
|
|
131
140
|
}, []);
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
if (!hueColor && value) {
|
|
134
|
-
setHueColor('#' + value);
|
|
135
|
-
}
|
|
136
|
-
}, [value, hueColor]);
|
|
137
141
|
useEffect(() => {
|
|
138
142
|
var _a, _b;
|
|
139
143
|
const hueHsv = (_b = (_a = hueRef.current) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.hsv;
|
|
140
|
-
if (
|
|
141
|
-
|
|
144
|
+
if (hueHsv) {
|
|
145
|
+
setHsv({ h: hueHsv.h, s: hueHsv.s, v: hueHsv.v });
|
|
142
146
|
}
|
|
143
|
-
|
|
144
|
-
h: hueHsv.h, s: 1, v: hueHsv.v, a: hueHsv.s
|
|
145
|
-
});
|
|
146
|
-
}, [hueRef.current]);
|
|
147
|
+
}, []);
|
|
147
148
|
return (React.createElement(ClickAwayListener, { onClickAway: handleClickAway },
|
|
148
149
|
React.createElement(Grow, Object.assign({}, TransitionProps, { timeout: 200 }),
|
|
149
150
|
React.createElement(Paper, { className: classes.paper },
|
|
150
151
|
React.createElement("span", { className: classes.arrow, "data-popper-arrow": true }),
|
|
151
|
-
React.createElement(HuePicker, { ref: hueRef, color: hueColor, onChange:
|
|
152
|
-
React.createElement(AlphaPicker, { className: classes.customAlfa, color: alfaColor, width: "168", onChange:
|
|
152
|
+
React.createElement(HuePicker, { ref: hueRef, color: hueColor, onChange: onHueChange, onChangeComplete: onSliderChangeComplete, width: "168", className: classes.bottomOffset }),
|
|
153
|
+
React.createElement(AlphaPicker, { className: classes.customAlfa, color: alfaColor, width: "168", onChange: onAlfaChange, onChangeComplete: onSliderChangeComplete }),
|
|
153
154
|
React.createElement("div", { className: classes.material },
|
|
154
155
|
React.createElement(MaterialPicker, { styles: {
|
|
155
156
|
default: {
|
|
156
157
|
material: { width: '100%', height: 'unset', padding: 0, fontFamily: 'inherit' }
|
|
157
158
|
}
|
|
158
|
-
}, color: hueColor, onChange:
|
|
159
|
+
}, color: hueColor, onChange: onMaterialChange, onChangeComplete: onMaterialChangeComplete }))))));
|
|
159
160
|
});
|
|
160
161
|
const ColorPickerWrapper = React.memo(({ input, placement = 'top', width }) => {
|
|
161
162
|
const { classes, cx } = useStyles();
|
package/dist/model/Fields.d.ts
CHANGED
|
@@ -32,9 +32,9 @@ export interface MenuTag<T> {
|
|
|
32
32
|
queryPrefix?: string;
|
|
33
33
|
indeterminate?: boolean;
|
|
34
34
|
}
|
|
35
|
-
export interface FieldInputProps {
|
|
35
|
+
export interface FieldInputProps<T = any> {
|
|
36
36
|
checked?: boolean | undefined;
|
|
37
|
-
value:
|
|
37
|
+
value: T;
|
|
38
38
|
name: string;
|
|
39
39
|
onBlur: EventOrValueHandler<FocusEvent<any>>;
|
|
40
40
|
onChange: EventOrValueHandler<ChangeEvent<any>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FieldInputProps, FieldMetaProps, TagLike, TagsFieldProps } from '../model';
|
|
3
|
-
declare function TagInputList<T extends TagLike, IP extends FieldInputProps
|
|
3
|
+
declare function TagInputList<T extends TagLike, IP extends FieldInputProps<TagLike['id'][]>, MP extends FieldMetaProps>({ input, tags, placeholder, labelAdornment, meta, label, disabled, className, warning, allowParentSelect, fieldClasses, editIcon, variant, hideColor, trackCarretPosition }: TagsFieldProps<T, IP, MP>): React.JSX.Element;
|
|
4
4
|
export default TagInputList;
|
|
@@ -110,8 +110,9 @@ function TagInputList({ input, tags, placeholder, labelAdornment, meta, label =
|
|
|
110
110
|
const tagMenuNode = useRef(undefined);
|
|
111
111
|
const menuTags = useMemo(() => (tags && input.value ? getMenuTags(tags.filter(t => allowParentSelect || t.childrenCount > 0), input.value) : []), [tags, input.value, allowParentSelect]);
|
|
112
112
|
const allMenuTags = useMemo(() => getAllMenuTags(menuTags), [menuTags]);
|
|
113
|
+
const normalizedValue = useMemo(() => { var _a; return ((_a = input === null || input === void 0 ? void 0 : input.value) === null || _a === void 0 ? void 0 : _a.filter(id => allMenuTags.some(t => t.tagBody.id === id))) || []; }, [input.value, allMenuTags]);
|
|
113
114
|
const onTagAdd = (tag) => {
|
|
114
|
-
const updated = [...
|
|
115
|
+
const updated = [...normalizedValue];
|
|
115
116
|
const index = updated.findIndex(id => id === tag.tagBody.id);
|
|
116
117
|
if (index !== -1) {
|
|
117
118
|
updated.splice(index, 1);
|
|
@@ -189,7 +190,7 @@ function TagInputList({ input, tags, placeholder, labelAdornment, meta, label =
|
|
|
189
190
|
return (React.createElement("div", { className: className, id: input.name },
|
|
190
191
|
React.createElement("div", { className: cx('relative', {
|
|
191
192
|
'pointer-events-none': disabled
|
|
192
|
-
}) }, React.createElement(Autocomplete, { value:
|
|
193
|
+
}) }, React.createElement(Autocomplete, { value: normalizedValue, multiple: true, open: menuIsOpen, options: filteredOptions, onBlur: exit, onChange: handleChange, renderOption: renderOption, filterOptions: filterOptionsInner, getOptionLabel: getOptionLabel, slots: {
|
|
193
194
|
popper: inputValue || !trackCarretPosition ? undefined : popperAdapter,
|
|
194
195
|
listbox: inputValue ? undefined : listboxAdapter
|
|
195
196
|
}, classes: {
|
|
@@ -224,12 +225,15 @@ function TagInputList({ input, tags, placeholder, labelAdornment, meta, label =
|
|
|
224
225
|
color: textColors.dark
|
|
225
226
|
}
|
|
226
227
|
} })));
|
|
227
|
-
}), renderInput: (_a) => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
228
|
+
}), renderInput: (_a) => {
|
|
229
|
+
var { slotProps: { input: InputProps, htmlInput: inputProps } } = _a, params = __rest(_a, ["slotProps"]);
|
|
230
|
+
return (React.createElement(EditInPlaceFieldBase, Object.assign({}, params, { value: inputValue, variant: variant, name: input.name, error: meta.error, invalid: meta === null || meta === void 0 ? void 0 : meta.invalid, label: label, warning: warning, disabled: disabled, fieldClasses: fieldClasses, shrink: Boolean(label || input.value), labelAdornment: labelAdornment, placeholder: normalizedValue.length ? '' : placeholder, editIcon: editIcon === undefined ? React.createElement(Edit, { className: classes.expandIcon }) : editIcon, InputProps: Object.assign(Object.assign({}, InputProps), { endAdornment: null, onChange: handleInputChange, onFocus, classes: {
|
|
231
|
+
underline: fieldClasses.underline,
|
|
232
|
+
input: cx(disabled && classes.readonly, fieldClasses.text),
|
|
233
|
+
}, inputProps: Object.assign(Object.assign({}, inputProps), { ref: ref => {
|
|
234
|
+
inputProps.ref.current = ref;
|
|
235
|
+
inputNode.current = ref;
|
|
236
|
+
}, className: cx(inputProps.className, fieldClasses.text, 'mr-auto') }) }) })));
|
|
237
|
+
}, popupIcon: stubComponent(), disableListWrap: true, openOnFocus: true }))));
|
|
234
238
|
}
|
|
235
239
|
export default TagInputList;
|