@sanity/color-input 2.36.0 → 2.36.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/LICENSE +1 -1
- package/lib/ColorInput.js +9 -3
- package/lib/ColorInput.js.map +1 -1
- package/package.json +1 -1
- package/src/ColorInput.js +10 -2
package/LICENSE
CHANGED
package/lib/ColorInput.js
CHANGED
|
@@ -79,11 +79,15 @@ class ColorInput extends _react.PureComponent {
|
|
|
79
79
|
type = _this$props2.type,
|
|
80
80
|
readOnly = _this$props2.readOnly,
|
|
81
81
|
value = _this$props2.value,
|
|
82
|
-
level = _this$props2.level
|
|
82
|
+
level = _this$props2.level,
|
|
83
|
+
markers = _this$props2.markers,
|
|
84
|
+
presence = _this$props2.presence;
|
|
83
85
|
return /*#__PURE__*/_react.default.createElement(_components.FormField, {
|
|
84
86
|
title: type.title,
|
|
85
87
|
description: type.description,
|
|
86
|
-
level: level
|
|
88
|
+
level: level,
|
|
89
|
+
__unstable_markers: markers,
|
|
90
|
+
__unstable_presence: presence
|
|
87
91
|
}, value ? /*#__PURE__*/_react.default.createElement(_ColorPicker.default, {
|
|
88
92
|
ref: this.focusRef,
|
|
89
93
|
color: value.hsl || value.hex,
|
|
@@ -116,6 +120,8 @@ _defineProperty(ColorInput, "propTypes", {
|
|
|
116
120
|
value: _propTypes.default.shape({
|
|
117
121
|
hex: _propTypes.default.string,
|
|
118
122
|
alpha: _propTypes.default.number
|
|
119
|
-
})
|
|
123
|
+
}),
|
|
124
|
+
markers: _propTypes.default.array,
|
|
125
|
+
presence: _propTypes.default.array
|
|
120
126
|
});
|
|
121
127
|
//# sourceMappingURL=ColorInput.js.map
|
package/lib/ColorInput.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorInput.js","names":["set","patches","unset","setIfMissing","DEFAULT_COLOR","hex","hsl","h","s","l","a","hsv","v","rgb","r","g","b","source","ColorInput","PureComponent","React","createRef","nextColor","props","onChange","type","fieldPatches","fields","filter","field","name","map","nextFieldValue","isObject","jsonType","Object","assign","_type","PatchEvent","from","debounce","emitSetColor","focus","focusRef","current","render","readOnly","value","level","title","description","handleColorChange","options","disableAlpha","handleUnset","AddIcon","Boolean","handleCreateColor","PropTypes","shape","string","arrayOf","isRequired","func","bool","alpha","number"],"sources":["../src/ColorInput.js"],"sourcesContent":["///<reference types=\"@sanity/types/parts\" />\n\n/* eslint-disable id-length */\nimport React, {PureComponent} from 'react'\nimport PropTypes from 'prop-types'\nimport {PatchEvent, patches} from 'part:@sanity/form-builder'\nimport {debounce} from 'lodash'\nimport {Button} from '@sanity/ui'\nimport {AddIcon} from '@sanity/icons'\nimport {FormField} from '@sanity/base/components'\nimport ColorPicker from './ColorPicker'\n\nconst {set, unset, setIfMissing} = patches\n\nconst DEFAULT_COLOR = {\n hex: '#24a3e3',\n hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},\n hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},\n rgb: {r: 46, g: 163, b: 227, a: 1},\n source: 'hex',\n}\n\nexport default class ColorInput extends PureComponent {\n focusRef = React.createRef()\n static propTypes = {\n type: PropTypes.shape({\n name: PropTypes.string,\n title: PropTypes.string,\n description: PropTypes.string,\n fields: PropTypes.arrayOf(\n PropTypes.shape({\n name: PropTypes.string.isRequired,\n })\n ),\n }).isRequired,\n onChange: PropTypes.func.isRequired,\n readOnly: PropTypes.bool,\n value: PropTypes.shape({\n hex: PropTypes.string,\n alpha: PropTypes.number,\n }),\n }\n\n focus() {\n // todo: make the ColorPicker component support .focus()\n if (this.focusRef.current && this.focusRef.current.focus) {\n this.focusRef.current.focus()\n }\n }\n\n emitSetColor = (nextColor) => {\n const {onChange, type} = this.props\n\n const fieldPatches = type.fields\n .filter((field) => field.name in nextColor)\n .map((field) => {\n const nextFieldValue = nextColor[field.name]\n const isObject = field.type.jsonType === 'object'\n return set(\n isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,\n [field.name]\n )\n })\n\n onChange(\n PatchEvent.from([\n setIfMissing({_type: type.name}),\n set(type.name, ['_type']),\n set(nextColor.rgb.a, ['alpha']),\n ...fieldPatches,\n ])\n )\n }\n\n // The color picker emits onChange events continuously while the user is sliding the\n // hue/saturation/alpha selectors. This debounces the event to avoid excessive patches\n handleColorChange = debounce(this.emitSetColor, 100)\n\n handleCreateColor = () => {\n this.emitSetColor(DEFAULT_COLOR)\n }\n\n handleUnset = () => {\n this.props.onChange(PatchEvent.from(unset()))\n }\n\n render() {\n const {type, readOnly, value, level} = this.props\n return (\n <FormField
|
|
1
|
+
{"version":3,"file":"ColorInput.js","names":["set","patches","unset","setIfMissing","DEFAULT_COLOR","hex","hsl","h","s","l","a","hsv","v","rgb","r","g","b","source","ColorInput","PureComponent","React","createRef","nextColor","props","onChange","type","fieldPatches","fields","filter","field","name","map","nextFieldValue","isObject","jsonType","Object","assign","_type","PatchEvent","from","debounce","emitSetColor","focus","focusRef","current","render","readOnly","value","level","markers","presence","title","description","handleColorChange","options","disableAlpha","handleUnset","AddIcon","Boolean","handleCreateColor","PropTypes","shape","string","arrayOf","isRequired","func","bool","alpha","number","array"],"sources":["../src/ColorInput.js"],"sourcesContent":["///<reference types=\"@sanity/types/parts\" />\n\n/* eslint-disable id-length */\nimport React, {PureComponent} from 'react'\nimport PropTypes from 'prop-types'\nimport {PatchEvent, patches} from 'part:@sanity/form-builder'\nimport {debounce} from 'lodash'\nimport {Button} from '@sanity/ui'\nimport {AddIcon} from '@sanity/icons'\nimport {FormField} from '@sanity/base/components'\nimport ColorPicker from './ColorPicker'\n\nconst {set, unset, setIfMissing} = patches\n\nconst DEFAULT_COLOR = {\n hex: '#24a3e3',\n hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},\n hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},\n rgb: {r: 46, g: 163, b: 227, a: 1},\n source: 'hex',\n}\n\nexport default class ColorInput extends PureComponent {\n focusRef = React.createRef()\n static propTypes = {\n type: PropTypes.shape({\n name: PropTypes.string,\n title: PropTypes.string,\n description: PropTypes.string,\n fields: PropTypes.arrayOf(\n PropTypes.shape({\n name: PropTypes.string.isRequired,\n })\n ),\n }).isRequired,\n onChange: PropTypes.func.isRequired,\n readOnly: PropTypes.bool,\n value: PropTypes.shape({\n hex: PropTypes.string,\n alpha: PropTypes.number,\n }),\n markers: PropTypes.array,\n presence: PropTypes.array,\n }\n\n focus() {\n // todo: make the ColorPicker component support .focus()\n if (this.focusRef.current && this.focusRef.current.focus) {\n this.focusRef.current.focus()\n }\n }\n\n emitSetColor = (nextColor) => {\n const {onChange, type} = this.props\n\n const fieldPatches = type.fields\n .filter((field) => field.name in nextColor)\n .map((field) => {\n const nextFieldValue = nextColor[field.name]\n const isObject = field.type.jsonType === 'object'\n return set(\n isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,\n [field.name]\n )\n })\n\n onChange(\n PatchEvent.from([\n setIfMissing({_type: type.name}),\n set(type.name, ['_type']),\n set(nextColor.rgb.a, ['alpha']),\n ...fieldPatches,\n ])\n )\n }\n\n // The color picker emits onChange events continuously while the user is sliding the\n // hue/saturation/alpha selectors. This debounces the event to avoid excessive patches\n handleColorChange = debounce(this.emitSetColor, 100)\n\n handleCreateColor = () => {\n this.emitSetColor(DEFAULT_COLOR)\n }\n\n handleUnset = () => {\n this.props.onChange(PatchEvent.from(unset()))\n }\n\n render() {\n const {type, readOnly, value, level, markers, presence} = this.props\n return (\n <FormField\n title={type.title}\n description={type.description}\n level={level}\n __unstable_markers={markers}\n __unstable_presence={presence}\n >\n {value ? (\n <ColorPicker\n ref={this.focusRef}\n color={value.hsl || value.hex}\n readOnly={readOnly || type.readOnly}\n onChange={this.handleColorChange}\n disableAlpha={type.options && type.options.disableAlpha}\n onUnset={this.handleUnset}\n />\n ) : (\n <Button\n icon={AddIcon}\n mode=\"ghost\"\n text=\"Create color\"\n ref={this.focusRef}\n disabled={Boolean(readOnly)}\n onClick={this.handleCreateColor}\n />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Ea,kBAAS,CAACC,KAAK,CAAC;IACrBxD,GAAG,EAAEuD,kBAAS,CAACE,MAAM;IACrBK,KAAK,EAAEP,kBAAS,CAACQ;EACnB,CAAC,CAAC;EACFnB,OAAO,EAAEW,kBAAS,CAACS,KAAK;EACxBnB,QAAQ,EAAEU,kBAAS,CAACS;AACtB,CAAC"}
|
package/package.json
CHANGED
package/src/ColorInput.js
CHANGED
|
@@ -39,6 +39,8 @@ export default class ColorInput extends PureComponent {
|
|
|
39
39
|
hex: PropTypes.string,
|
|
40
40
|
alpha: PropTypes.number,
|
|
41
41
|
}),
|
|
42
|
+
markers: PropTypes.array,
|
|
43
|
+
presence: PropTypes.array,
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
focus() {
|
|
@@ -85,9 +87,15 @@ export default class ColorInput extends PureComponent {
|
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
render() {
|
|
88
|
-
const {type, readOnly, value, level} = this.props
|
|
90
|
+
const {type, readOnly, value, level, markers, presence} = this.props
|
|
89
91
|
return (
|
|
90
|
-
<FormField
|
|
92
|
+
<FormField
|
|
93
|
+
title={type.title}
|
|
94
|
+
description={type.description}
|
|
95
|
+
level={level}
|
|
96
|
+
__unstable_markers={markers}
|
|
97
|
+
__unstable_presence={presence}
|
|
98
|
+
>
|
|
91
99
|
{value ? (
|
|
92
100
|
<ColorPicker
|
|
93
101
|
ref={this.focusRef}
|