@sanity/color-input 2.35.2 → 2.36.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016 - 2022 Sanity.io
3
+ Copyright (c) 2022 - 2022 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,11 +1,21 @@
1
1
  # @sanity/color-input
2
2
 
3
+ > This is a **Sanity Studio v2** plugin.
4
+ > For the v3 version, please refer to the [v3-branch](https://github.com/sanity-io/color-input).
5
+
3
6
  Color input for [Sanity](https://sanity.io/) that stores selected colors in hex, hsl, hsv and rgb format.
4
7
 
5
8
  ## Installation
6
9
 
10
+ ```sh
11
+ yarn add @sanity/color-input@studio-v2
7
12
  ```
8
- sanity install @sanity/color-input
13
+
14
+ Next, add `"@sanity/color-input"` to `sanity.json` plugins array:
15
+ ```json
16
+ "plugins": [
17
+ "@sanity/color-input"
18
+ ]
9
19
  ```
10
20
 
11
21
  ## Usage
package/lib/ColorInput.js CHANGED
@@ -4,17 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _debounce2 = _interopRequireDefault(require("lodash/debounce"));
8
7
  var _react = _interopRequireWildcard(require("react"));
9
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
9
  var _formBuilder = require("part:@sanity/form-builder");
10
+ var _lodash = require("lodash");
11
11
  var _ui = require("@sanity/ui");
12
12
  var _icons = require("@sanity/icons");
13
13
  var _components = require("@sanity/base/components");
14
14
  var _ColorPicker = _interopRequireDefault(require("./ColorPicker"));
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
16
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
17
  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; }
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
19
  var set = _formBuilder.patches.set,
20
20
  unset = _formBuilder.patches.unset,
@@ -60,7 +60,7 @@ class ColorInput extends _react.PureComponent {
60
60
  _type: type.name
61
61
  }), set(type.name, ['_type']), set(nextColor.rgb.a, ['alpha']), ...fieldPatches]));
62
62
  });
63
- _defineProperty(this, "handleColorChange", (0, _debounce2.default)(this.emitSetColor, 100));
63
+ _defineProperty(this, "handleColorChange", (0, _lodash.debounce)(this.emitSetColor, 100));
64
64
  _defineProperty(this, "handleCreateColor", () => {
65
65
  this.emitSetColor(DEFAULT_COLOR);
66
66
  });
@@ -117,4 +117,5 @@ _defineProperty(ColorInput, "propTypes", {
117
117
  hex: _propTypes.default.string,
118
118
  alpha: _propTypes.default.number
119
119
  })
120
- });
120
+ });
121
+ //# sourceMappingURL=ColorInput.js.map
@@ -0,0 +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 title={type.title} description={type.description} level={level}>\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 />\n )}\n </FormField>\n )\n }\n}\n"],"mappings":";;;;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAuC;AAAA;AAAA;AAAA;AAEvC,IAAOA,GAAG,GAAyBC,oBAAO,CAAnCD,GAAG;EAAEE,KAAK,GAAkBD,oBAAO,CAA9BC,KAAK;EAAEC,YAAY,GAAIF,oBAAO,CAAvBE,YAAY;AAE/B,IAAMC,aAAa,GAAG;EACpBC,GAAG,EAAE,SAAS;EACdC,GAAG,EAAE;IAACC,CAAC,EAAE,GAAG;IAAEC,CAAC,EAAE,MAAM;IAAEC,CAAC,EAAE,MAAM;IAAEC,CAAC,EAAE;EAAC,CAAC;EACzCC,GAAG,EAAE;IAACJ,CAAC,EAAE,GAAG;IA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EAAC,cAAc;MACnB,GAAG,EAAE,IAAI,CAACZ,QAAS;MACnB,QAAQ,EAAEa,OAAO,CAACV,QAAQ,CAAE;MAC5B,OAAO,EAAE,IAAI,CAACW;IAAkB,EAEnC,CACS;EAEhB;AACF;AAAC;AAAA,gBA1FoBvC,UAAU,eAEV;EACjBO,IAAI,EAAEiC,kBAAS,CAACC,KAAK,CAAC;IACpB7B,IAAI,EAAE4B,kBAAS,CAACE,MAAM;IACtBX,KAAK,EAAES,kBAAS,CAACE,MAAM;IACvBV,WAAW,EAAEQ,kBAAS,CAACE,MAAM;IAC7BjC,MAAM,EAAE+B,kBAAS,CAACG,OAAO,CACvBH,kBAAS,CAACC,KAAK,CAAC;MACd7B,IAAI,EAAE4B,kBAAS,CAACE,MAAM,CAACE;IACzB,CAAC,CAAC;EAEN,CAAC,CAAC,CAACA,UAAU;EACbtC,QAAQ,EAAEkC,kBAAS,CAACK,IAAI,CAACD,UAAU;EACnChB,QAAQ,EAAEY,kBAAS,CAACM,IAAI;EACxBjB,KAAK,EAAEW,kBAAS,CAACC,KAAK,CAAC;IACrBtD,GAAG,EAAEqD,kBAAS,CAACE,MAAM;IACrBK,KAAK,EAAEP,kBAAS,CAACQ;EACnB,CAAC;AACH,CAAC"}
@@ -141,4 +141,5 @@ ColorPicker.defaultProps = {
141
141
  disableAlpha: false
142
142
  };
143
143
  var _default = (0, _common.ColorWrap)(ColorPicker);
144
- exports.default = _default;
144
+ exports.default = _default;
145
+ //# sourceMappingURL=ColorPicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPicker.js","names":["ColorBox","styled","Box","ReadOnlyContainer","Flex","ColorPicker","width","rgb","hex","hsv","hsl","onChange","onUnset","disableAlpha","renderers","readOnly","position","height","minWidth","backgroundColor","r","g","b","a","Math","round","h","s","l","TrashIcon","propTypes","PropTypes","string","object","func","bool","defaultProps","ColorWrap"],"sources":["../src/ColorPicker.js"],"sourcesContent":["import React from 'react'\nimport PropTypes from 'prop-types'\nimport {ColorWrap, Checkboard, Saturation, Hue, Alpha} from 'react-color/lib/components/common'\nimport {Box, Card, Flex, Button, Inline, Stack, Text} from '@sanity/ui'\nimport {TrashIcon} from '@sanity/icons'\nimport styled from 'styled-components'\nimport {ColorPickerFields} from './ColorPickerFields'\n\nconst ColorBox = styled(Box)`\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n`\n\nconst ReadOnlyContainer = styled(Flex)`\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n`\n\nconst ColorPicker = ({\n width,\n rgb,\n hex,\n hsv,\n hsl,\n onChange,\n onUnset,\n disableAlpha,\n renderers,\n readOnly,\n}) => {\n return (\n <div style={{width}}>\n <Card padding={1} border radius={1}>\n <Stack space={2}>\n {!readOnly && (\n <>\n <Card overflow=\"hidden\" style={{position: 'relative', height: '5em'}}>\n <Saturation is=\"Saturation\" onChange={onChange} hsl={hsl} hsv={hsv} />\n </Card>\n\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Hue is=\"Hue\" hsl={hsl} onChange={!readOnly && onChange} />\n </Card>\n\n {!disableAlpha && (\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Alpha is=\"Alpha\" rgb={rgb} hsl={hsl} renderers={renderers} onChange={onChange} />\n </Card>\n )}\n </>\n )}\n <Flex>\n <Card\n flex={1}\n radius={2}\n overflow=\"hidden\"\n style={{position: 'relative', minWidth: '4em'}}\n >\n <Checkboard />\n <ColorBox style={{backgroundColor: `rgba(${rgb.r},${rgb.g},${rgb.b},${rgb.a})`}} />\n\n {readOnly && (\n <ReadOnlyContainer\n padding={2}\n paddingBottom={1}\n sizing=\"border\"\n justify=\"space-between\"\n >\n <Stack space={3} marginTop={1}>\n <Text size={3} weight=\"bold\">\n {hex}\n </Text>\n\n <Inline space={3}>\n <Text size={1}>\n <strong>RGB: </strong>\n {rgb.r} {rgb.g} {rgb.b}\n </Text>\n <Text size={1}>\n <strong>HSL: </strong> {Math.round(hsl.h)} {Math.round(hsl.s)}%{' '}\n {Math.round(hsl.l)}\n </Text>\n </Inline>\n </Stack>\n </ReadOnlyContainer>\n )}\n </Card>\n\n {!readOnly && (\n <Flex align=\"flex-start\" marginLeft={2}>\n <Box style={{width: 200}}>\n <ColorPickerFields\n rgb={rgb}\n hsl={hsl}\n hex={hex}\n onChange={onChange}\n disableAlpha={disableAlpha}\n />\n </Box>\n <Box marginLeft={2}>\n <Button onClick={onUnset} title=\"Delete color\" icon={TrashIcon} tone=\"critical\" />\n </Box>\n </Flex>\n )}\n </Flex>\n </Stack>\n </Card>\n </div>\n )\n}\n\nColorPicker.propTypes = {\n width: PropTypes.string,\n hex: PropTypes.string,\n hsl: PropTypes.object,\n hsv: PropTypes.object,\n rgb: PropTypes.object,\n onChange: PropTypes.func,\n disableAlpha: PropTypes.bool,\n readOnly: PropTypes.bool,\n renderers: PropTypes.func,\n onUnset: PropTypes.func,\n}\n\nColorPicker.defaultProps = {\n disableAlpha: false,\n}\n\nexport default ColorWrap(ColorPicker)\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAAqD;AAAA;AAAA;AAErD,IAAMA,QAAQ,GAAG,IAAAC,yBAAM,EAACC,OAAG,CAAC,sJAM3B;AAED,IAAMC,iBAAiB,GAAG,IAAAF,yBAAM,EAACG,QAAI,CAAC,gLAKrC;AAED,IAAMC,WAAW,GAAG,QAWd;EAAA,IAVJC,KAAK,QAALA,KAAK;IACLC,GAAG,QAAHA,GAAG;IACHC,GAAG,QAAHA,GAAG;IACHC,GAAG,QAAHA,GAAG;IACHC,GAAG,QAAHA,GAAG;IACHC,QAAQ,QAARA,QAAQ;IACRC,OAAO,QAAPA,OAAO;IACPC,YAAY,QAAZA,YAAY;IACZC,SAAS,QAATA,SAAS;IACTC,QAAQ,QAARA,QAAQ;EAER,oBACE;IAAK,KAAK,EAAE;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IACnB,YAAY,EAAEE;EAAa,EAC3B,CACE,eACN,6BAAC,OAAG;IAAC,UAAU,EAAE;EAAE,gBACjB,6BAAC,UAAM;IAAC,OAAO,EAAED,OAAQ;IAAC,KAAK,EAAC,cAAc;IAAC,IAAI,EAAEiB,gBAAU;IAAC,IAAI,EAAC;EAAU,EAAG,CAC9E,CAET,CACI,CACD,CACH,CACH;AAEV,CAAC;AAEDxB,WAAW,CAACyB,SAAS,GAAG;EACtBxB,KAAK,EAAEyB,kBAAS,CAACC,MAAM;EACvBxB,GAAG,EAAEuB,kBAAS,CAACC,MAAM;EACrBtB,GAAG,EAAEqB,kBAAS,CAACE,MAAM;EACrBxB,GAAG,EAAEsB,kBAAS,CAACE,MAAM;EACrB1B,GAAG,EAAEwB,kBAAS,CAACE,MAAM;EACrBtB,QAAQ,EAAEoB,kBAAS,CAACG,IAAI;EACxBrB,YAAY,EAAEkB,kBAAS,CAACI,IAAI;EAC5BpB,QAAQ,EAAEgB,kBAAS,CAACI,IAAI;EACxBrB,SAAS,EAAEiB,kBAAS,CAACG,IAAI;EACzBtB,OAAO,EAAEmB,kBAAS,CAACG;AACrB,CAAC;AAED7B,WAAW,CAAC+B,YAAY,GAAG;EACzBvB,YAAY,EAAE;AAChB,CAAC;AAAA,eAEc,IAAAwB,iBAAS,EAAChC,WAAW,CAAC;AAAA"}
@@ -121,4 +121,5 @@ var ColorPickerFields = _ref => {
121
121
  };
122
122
  exports.ColorPickerFields = ColorPickerFields;
123
123
  var _default = ColorPickerFields;
124
- exports.default = _default;
124
+ exports.default = _default;
125
+ //# sourceMappingURL=ColorPickerFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorPickerFields.js","names":["ColorPickerFields","onChange","rgb","hsl","hex","disableAlpha","useTheme","sanity","inputStyles","input","width","padding","border","boxShadow","color","default","enabled","fg","backgroundColor","bg","fontSize","fonts","text","sizes","textAlign","label","display","base","paddingTop","paddingBottom","textTransform","handleChange","data","e","isValidHex","source","r","g","b","a","h","s","l","replace","Math","round"],"sources":["../src/ColorPickerFields.js"],"sourcesContent":["import React from 'react'\nimport * as color from 'react-color/lib/helpers/color'\nimport {EditableInput} from 'react-color/lib/components/common'\nimport {Box, Flex, useTheme} from '@sanity/ui'\n\nexport const ColorPickerFields = ({onChange, rgb, hsl, hex, disableAlpha}) => {\n const {sanity} = useTheme()\n\n const inputStyles = {\n input: {\n width: '80%',\n padding: '4px 10% 3px',\n border: 'none',\n boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,\n color: sanity.color.input.default.enabled.fg,\n backgroundColor: sanity.color.input.default.enabled.bg,\n fontSize: sanity.fonts.text.sizes[0].fontSize,\n textAlign: 'center',\n },\n label: {\n display: 'block',\n textAlign: 'center',\n fontSize: sanity.fonts.label.sizes[0].fontSize,\n color: sanity.color.base.fg,\n paddingTop: '3px',\n paddingBottom: '4px',\n textTransform: 'capitalize',\n },\n }\n\n const handleChange = (data, e) => {\n if (data.hex && color.isValidHex(data.hex)) {\n onChange(\n {\n hex: data.hex,\n source: 'hex',\n },\n e\n )\n } else if (data.r || data.g || data.b) {\n onChange(\n {\n r: data.r || rgb.r,\n g: data.g || rgb.g,\n b: data.b || rgb.b,\n a: rgb.a,\n source: 'rgb',\n },\n e\n )\n } else if (data.a) {\n if (data.a < 0) {\n data.a = 0\n } else if (data.a > 100) {\n data.a = 100\n }\n\n data.a /= 100\n onChange(\n {\n h: hsl.h,\n s: hsl.s,\n l: hsl.l,\n a: data.a,\n source: 'rgb',\n },\n e\n )\n }\n }\n\n return (\n <Flex>\n <Box flex={2} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"hex\"\n value={hex.replace('#', '')}\n onChange={handleChange}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"r\"\n value={rgb.r}\n onChange={handleChange}\n dragLabel=\"true\"\n dragMax=\"255\"\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"g\"\n value={rgb.g}\n onChange={handleChange}\n dragLabel=\"true\"\n dragMax=\"255\"\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"b\"\n value={rgb.b}\n onChange={handleChange}\n dragLabel=\"true\"\n dragMax=\"255\"\n />\n </Box>\n {!disableAlpha && (\n <Box flex={1}>\n <EditableInput\n style={inputStyles}\n label=\"a\"\n value={Math.round(rgb.a * 100)}\n onChange={handleChange}\n dragLabel=\"true\"\n dragMax=\"100\"\n />\n </Box>\n )}\n </Flex>\n )\n}\n\nexport default ColorPickerFields\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAA8C;AAAA;AAAA;AAEvC,IAAMA,iBAAiB,GAAG,QAA6C;EAAA,IAA3CC,QAAQ,QAARA,QAAQ;IAAEC,GAAG,QAAHA,GAAG;IAAEC,GAAG,QAAHA,GAAG;IAAEC,GAAG,QAAHA,GAAG;IAAEC,YAAY,QAAZA,YAAY;EACtE,gBAAiB,IAAAC,YAAQ,GAAE;IAApBC,MAAM,aAANA,MAAM;EAEb,IAAMC,WAAW,GAAG;IAClBC,KAAK,EAAE;MACLC,KAAK,EAAE,KAAK;MACZC,OAAO,EAAE,aAAa;MACtBC,MAAM,EAAE,MAAM;MACdC,SAAS,4BAAqBN,MAAM,CAACO,KAAK,CAACL,KAAK,CAACM,OAAO,CAACC,OAAO,CAACJ,MAAM,CAAE;MACzEE,KAAK,EAAEP,MAAM,CAACO,KAAK,CAACL,KAAK,CAACM,OAAO,CAACC,OAAO,CAACC,EAAE;MAC5CC,eAAe,EAAEX,MAAM,CAACO,KAAK,CAACL,KAAK,CAACM,OAAO,CAACC,OAAO,CAACG,EAAE;MACtDC,QAAQ,EAAEb,MAAM,CAACc,KAAK,CAACC,IAAI,CAACC,KAAK,CAAC,CAAC,CAAC,CAACH,QAAQ;MAC7CI,SAAS,EAAE;IACb,CAAC;IACDC,KAAK,EAAE;MACLC,OAAO,EAAE,OAAO;MAChBF,SAAS,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AAO,EAAC;EAAK,EACb,CACE,EACL,CAAC1B,YAAY,iBACZ,6BAAC,OAAG;IAAC,IAAI,EAAE;EAAE,gBACX,6BAAC,qBAAa;IACZ,KAAK,EAAEG,WAAY;IACnB,KAAK,EAAC,GAAG;IACT,KAAK,EAAEoC,IAAI,CAACC,KAAK,CAAC3C,GAAG,CAACqC,CAAC,GAAG,GAAG,CAAE;IAC/B,QAAQ,EAAER,YAAa;IACvB,SAAS,EAAC,MAAM;IAChB,OAAO,EAAC;EAAK,EACb,CAEL,CACI;AAEX,CAAC;AAAA;AAAA,eAEc/B,iBAAiB;AAAA"}
@@ -70,4 +70,5 @@ var _default = {
70
70
  }
71
71
  }
72
72
  };
73
- exports.default = _default;
73
+ exports.default = _default;
74
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.js","names":["round","val","Math","name","type","title","inputComponent","ColorInput","fields","preview","select","alpha","hex","hsl","prepare","subtitle","l","media","backgroundColor","opacity","position","height","width","top","left"],"sources":["../../src/schemas/color.js"],"sourcesContent":["/* eslint-disable react/display-name */\nimport React from 'react'\nimport ColorInput from '../ColorInput'\n\nconst round = (val) => Math.round(val * 100)\n\nexport default {\n name: 'color',\n type: 'object',\n title: 'Color',\n inputComponent: ColorInput,\n fields: [\n {\n title: 'Hex',\n name: 'hex',\n type: 'string',\n },\n {\n title: 'Alpha',\n name: 'alpha',\n type: 'number',\n },\n {\n title: 'Hue Saturation Lightness',\n name: 'hsl',\n type: 'hslaColor',\n },\n {\n title: 'Hue Saturation Value',\n name: 'hsv',\n type: 'hsvaColor',\n },\n {\n title: 'Red Green Blue (rgb)',\n name: 'rgb',\n type: 'rgbaColor',\n },\n ],\n preview: {\n select: {\n title: 'hex',\n alpha: 'alpha',\n hex: 'hex',\n hsl: 'hsl',\n },\n prepare({title, hex, hsl, alpha}) {\n let subtitle = hex || 'No color set'\n if (hsl) {\n subtitle = `H:${round(hsl.l)} S:${round(hsl.l)} L:${round(hsl.l)} A:${round(alpha)}`\n }\n return {\n title: title,\n subtitle: subtitle,\n media: () => (\n <div\n style={{\n backgroundColor: hex || '#000',\n opacity: alpha || 1,\n position: 'absolute',\n height: '100%',\n width: '100%',\n top: '0',\n left: '0',\n }}\n />\n ),\n }\n },\n },\n}\n"],"mappings":";;;;;;AACA;AACA;AAAsC;AAFtC;;AAIA,IAAMA,KAAK,GAAIC,GAAG,IAAKC,IAAI,CAACF,KAAK,CAACC,GAAG,GAAG,GAAG,CAAC;AAAA,eAE7B;EACbE,IAAI,EAAE,OAAO;EACbC,IAAI,EAAE,QAAQ;EACdC,KAAK,EAAE,OAAO;EACdC,cAAc,EAAEC,mBAAU;EAC1BC,MAAM,EAAE,CACN;IACEH,KAAK,EAAE,KAAK;IACZF,IAAI,EAAE,KAAK;IACXC,IAAI,EAAE;EACR,CAAC,EACD;IACEC,KAAK,EAAE,OAAO;IACdF,IAAI,EAAE,OAAO;IACbC,IAAI,EAAE;EACR,CAAC,EACD;IACEC,KAAK,EAAE,0BAA0B;IACjCF,IAAI,EAAE,KAAK;IACXC,IAAI,EAAE;EACR,CAAC,EACD;IACEC,KAAK,EAAE,sBAAsB;IAC7BF,IAAI,EAAE,KAAK;IACXC,IAAI,EAAE;EACR,CAAC,EACD;IACEC,KAAK,EAAE,sBAAsB;IAC7BF,IAAI,EAAE,KAAK;IACXC,IAAI,EAAE;EACR,CAAC,CACF;EACDK,OAAO,EAAE;IACPC,MAAM,EAAE;MACNL,KAAK,EAAE,KAAK;MACZM,KAAK,EAAE,OAAO;MACdC,GAAG,EAAE,KAAK;MACVC,GAAG,EAAE;IACP,CAAC;IACDC,OAAO,OAA2B;MAAA,IAAzBT,KAAK,QAALA,KAAK;QAAEO,GAAG,QAAHA,GAAG;QAAEC,GAAG,QAAHA,GAAG;QAAEF,KAAK,QAALA,KAAK;MAC7B,IAAII,QAAQ,GAAGH,GAAG,IAAI,cAAc;MACpC,IAAIC,GAAG,EAAE;QACPE,QAAQ,eAAQf,KAAK,CAACa,GAAG,CAACG,CAAC,CAAC,gBAAMhB,KAAK,CAACa,GAAG,CAACG,CAAC,CAAC,gBAAMhB,KAAK,CAACa,GAAG,CAACG,CAAC,CAAC,gBAAMhB,KAAK,CAACW,KAAK,CAAC,CAAE;MACtF;MACA,OAAO;QACLN,KAAK,EAAEA,KAAK;QACZU,QAAQ,EAAEA,QAAQ;QAClBE,KAAK,EAAE,mBACL;UACE,KAAK,EAAE;YACLC,eAAe,EAAEN,GAAG,IAAI,MAAM;YAC9BO,OAAO,EAAER,KAAK,IAAI,CAAC;YACnBS,QAAQ,EAAE,UAAU;YACpBC,MAAM,EAAE,MAAM;YACdC,KAAK,EAAE,MAAM;YACbC,GAAG,EAAE,GAAG;YACRC,IAAI,EAAE;UACR;QAAE;MAGR,CAAC;IACH;EACF;AACF,CAAC;AAAA"}
@@ -26,4 +26,5 @@ var _default = {
26
26
  title: 'Alpha'
27
27
  }]
28
28
  };
29
- exports.default = _default;
29
+ exports.default = _default;
30
+ //# sourceMappingURL=hslaColor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hslaColor.js","names":["title","name","type","fields"],"sources":["../../src/schemas/hslaColor.js"],"sourcesContent":["export default {\n title: 'Hue Saturation Lightness',\n name: 'hslaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'l', type: 'number', title: 'Lightness'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n}\n"],"mappings":";;;;;;eAAe;EACbA,KAAK,EAAE,0BAA0B;EACjCC,IAAI,EAAE,WAAW;EACjBC,IAAI,EAAE,QAAQ;EACdC,MAAM,EAAE,CACN;IAACF,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAK,CAAC,EACzC;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAY,CAAC,EAChD;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAW,CAAC,EAC/C;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAO,CAAC;AAE/C,CAAC;AAAA"}
@@ -26,4 +26,5 @@ var _default = {
26
26
  title: 'Alpha'
27
27
  }]
28
28
  };
29
- exports.default = _default;
29
+ exports.default = _default;
30
+ //# sourceMappingURL=hsvaColor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hsvaColor.js","names":["title","name","type","fields"],"sources":["../../src/schemas/hsvaColor.js"],"sourcesContent":["export default {\n title: 'Hue Saturation Value',\n name: 'hsvaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'v', type: 'number', title: 'Value'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n}\n"],"mappings":";;;;;;eAAe;EACbA,KAAK,EAAE,sBAAsB;EAC7BC,IAAI,EAAE,WAAW;EACjBC,IAAI,EAAE,QAAQ;EACdC,MAAM,EAAE,CACN;IAACF,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAK,CAAC,EACzC;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAY,CAAC,EAChD;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAO,CAAC,EAC3C;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAO,CAAC;AAE/C,CAAC;AAAA"}
@@ -26,4 +26,5 @@ var _default = {
26
26
  title: 'Alpha'
27
27
  }]
28
28
  };
29
- exports.default = _default;
29
+ exports.default = _default;
30
+ //# sourceMappingURL=rgbaColor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgbaColor.js","names":["title","name","type","fields"],"sources":["../../src/schemas/rgbaColor.js"],"sourcesContent":["export default {\n title: 'Red Green Blue (rgb)',\n name: 'rgbaColor',\n type: 'object',\n fields: [\n {name: 'r', type: 'number', title: 'Red'},\n {name: 'g', type: 'number', title: 'Green'},\n {name: 'b', type: 'number', title: 'Blue'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n}\n"],"mappings":";;;;;;eAAe;EACbA,KAAK,EAAE,sBAAsB;EAC7BC,IAAI,EAAE,WAAW;EACjBC,IAAI,EAAE,QAAQ;EACdC,MAAM,EAAE,CACN;IAACF,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAK,CAAC,EACzC;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAO,CAAC,EAC3C;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAM,CAAC,EAC1C;IAACC,IAAI,EAAE,GAAG;IAAEC,IAAI,EAAE,QAAQ;IAAEF,KAAK,EAAE;EAAO,CAAC;AAE/C,CAAC;AAAA"}
package/package.json CHANGED
@@ -1,13 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/color-input",
3
- "version": "2.35.2",
4
- "description": "Color input",
5
- "main": "lib/index.js",
6
- "author": "Sanity.io <hello@sanity.io>",
7
- "license": "MIT",
8
- "scripts": {
9
- "clean": "rimraf lib dest"
10
- },
3
+ "version": "2.36.0",
4
+ "description": "Color input for Sanity Studio",
11
5
  "keywords": [
12
6
  "sanity",
13
7
  "cms",
@@ -17,6 +11,31 @@
17
11
  "color-input",
18
12
  "sanity-plugin"
19
13
  ],
14
+ "homepage": "https://www.sanity.io/",
15
+ "bugs": {
16
+ "url": "https://github.com/sanity-io/color-input/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git@github.com:sanity-io/color-input.git"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Sanity.io <hello@sanity.io>",
24
+ "main": "lib/schemas/color.js",
25
+ "files": [
26
+ "lib",
27
+ "src",
28
+ "sanity.json"
29
+ ],
30
+ "scripts": {
31
+ "prebuild": "npm run clean",
32
+ "build": "sanipack build",
33
+ "clean": "rimraf lib",
34
+ "lint": "eslint .",
35
+ "prepare": "husky install",
36
+ "prepublishOnly": "sanipack build",
37
+ "watch": "sanipack build --watch"
38
+ },
20
39
  "dependencies": {
21
40
  "@sanity/icons": "^1.3.4",
22
41
  "@sanity/ui": "^0.37.22",
@@ -24,10 +43,24 @@
24
43
  "react-color": "^2.13.8"
25
44
  },
26
45
  "devDependencies": {
46
+ "@commitlint/cli": "^17.3.0",
47
+ "@commitlint/config-conventional": "^17.3.0",
27
48
  "@sanity/base": "2.35.2",
49
+ "@sanity/semantic-release-preset": "^2.0.1",
28
50
  "@sanity/types": "2.35.0",
51
+ "eslint": "^8.27.0",
52
+ "eslint-config-prettier": "^8.5.0",
53
+ "eslint-config-sanity": "^6.0.0",
54
+ "eslint-plugin-prettier": "^4.2.1",
55
+ "eslint-plugin-react": "^7.31.10",
56
+ "eslint-plugin-react-hooks": "^4.6.0",
57
+ "husky": "^8.0.1",
58
+ "lint-staged": "^13.0.3",
59
+ "prettier": "^2.7.1",
60
+ "prettier-plugin-packagejson": "^2.3.0",
29
61
  "react": "17.0.1",
30
- "rimraf": "^2.7.1"
62
+ "rimraf": "^2.7.1",
63
+ "sanipack": "^2.1.0"
31
64
  },
32
65
  "peerDependencies": {
33
66
  "@sanity/base": "^2.14",
@@ -36,17 +69,7 @@
36
69
  "react": "^16.9 || ^17",
37
70
  "styled-components": "^5.2.0"
38
71
  },
39
- "bugs": {
40
- "url": "https://github.com/sanity-io/sanity/issues"
41
- },
42
- "homepage": "https://www.sanity.io/",
43
- "repository": {
44
- "type": "git",
45
- "url": "git+https://github.com/sanity-io/sanity.git",
46
- "directory": "packages/@sanity/color-input"
47
- },
48
72
  "publishConfig": {
49
73
  "access": "public"
50
- },
51
- "gitHead": "9bf408d4cc8b3e14bac0bf94d3305d6960181d3c"
74
+ }
52
75
  }
package/sanity.json CHANGED
@@ -5,11 +5,11 @@
5
5
  },
6
6
  "parts": [
7
7
  {
8
- "name": "part:@sanity/form-builder/input/color",
8
+ "name": "part:@sanity/color-input/input/color",
9
9
  "description": "Color input"
10
10
  },
11
11
  {
12
- "implements": "part:@sanity/form-builder/input/color",
12
+ "implements": "part:@sanity/color-input/input/color",
13
13
  "path": "ColorInput"
14
14
  },
15
15
  {
@@ -0,0 +1,113 @@
1
+ ///<reference types="@sanity/types/parts" />
2
+
3
+ /* eslint-disable id-length */
4
+ import React, {PureComponent} from 'react'
5
+ import PropTypes from 'prop-types'
6
+ import {PatchEvent, patches} from 'part:@sanity/form-builder'
7
+ import {debounce} from 'lodash'
8
+ import {Button} from '@sanity/ui'
9
+ import {AddIcon} from '@sanity/icons'
10
+ import {FormField} from '@sanity/base/components'
11
+ import ColorPicker from './ColorPicker'
12
+
13
+ const {set, unset, setIfMissing} = patches
14
+
15
+ const DEFAULT_COLOR = {
16
+ hex: '#24a3e3',
17
+ hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},
18
+ hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},
19
+ rgb: {r: 46, g: 163, b: 227, a: 1},
20
+ source: 'hex',
21
+ }
22
+
23
+ export default class ColorInput extends PureComponent {
24
+ focusRef = React.createRef()
25
+ static propTypes = {
26
+ type: PropTypes.shape({
27
+ name: PropTypes.string,
28
+ title: PropTypes.string,
29
+ description: PropTypes.string,
30
+ fields: PropTypes.arrayOf(
31
+ PropTypes.shape({
32
+ name: PropTypes.string.isRequired,
33
+ })
34
+ ),
35
+ }).isRequired,
36
+ onChange: PropTypes.func.isRequired,
37
+ readOnly: PropTypes.bool,
38
+ value: PropTypes.shape({
39
+ hex: PropTypes.string,
40
+ alpha: PropTypes.number,
41
+ }),
42
+ }
43
+
44
+ focus() {
45
+ // todo: make the ColorPicker component support .focus()
46
+ if (this.focusRef.current && this.focusRef.current.focus) {
47
+ this.focusRef.current.focus()
48
+ }
49
+ }
50
+
51
+ emitSetColor = (nextColor) => {
52
+ const {onChange, type} = this.props
53
+
54
+ const fieldPatches = type.fields
55
+ .filter((field) => field.name in nextColor)
56
+ .map((field) => {
57
+ const nextFieldValue = nextColor[field.name]
58
+ const isObject = field.type.jsonType === 'object'
59
+ return set(
60
+ isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,
61
+ [field.name]
62
+ )
63
+ })
64
+
65
+ onChange(
66
+ PatchEvent.from([
67
+ setIfMissing({_type: type.name}),
68
+ set(type.name, ['_type']),
69
+ set(nextColor.rgb.a, ['alpha']),
70
+ ...fieldPatches,
71
+ ])
72
+ )
73
+ }
74
+
75
+ // The color picker emits onChange events continuously while the user is sliding the
76
+ // hue/saturation/alpha selectors. This debounces the event to avoid excessive patches
77
+ handleColorChange = debounce(this.emitSetColor, 100)
78
+
79
+ handleCreateColor = () => {
80
+ this.emitSetColor(DEFAULT_COLOR)
81
+ }
82
+
83
+ handleUnset = () => {
84
+ this.props.onChange(PatchEvent.from(unset()))
85
+ }
86
+
87
+ render() {
88
+ const {type, readOnly, value, level} = this.props
89
+ return (
90
+ <FormField title={type.title} description={type.description} level={level}>
91
+ {value ? (
92
+ <ColorPicker
93
+ ref={this.focusRef}
94
+ color={value.hsl || value.hex}
95
+ readOnly={readOnly || type.readOnly}
96
+ onChange={this.handleColorChange}
97
+ disableAlpha={type.options && type.options.disableAlpha}
98
+ onUnset={this.handleUnset}
99
+ />
100
+ ) : (
101
+ <Button
102
+ icon={AddIcon}
103
+ mode="ghost"
104
+ text="Create color"
105
+ ref={this.focusRef}
106
+ disabled={Boolean(readOnly)}
107
+ onClick={this.handleCreateColor}
108
+ />
109
+ )}
110
+ </FormField>
111
+ )
112
+ }
113
+ }
@@ -0,0 +1,144 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import {ColorWrap, Checkboard, Saturation, Hue, Alpha} from 'react-color/lib/components/common'
4
+ import {Box, Card, Flex, Button, Inline, Stack, Text} from '@sanity/ui'
5
+ import {TrashIcon} from '@sanity/icons'
6
+ import styled from 'styled-components'
7
+ import {ColorPickerFields} from './ColorPickerFields'
8
+
9
+ const ColorBox = styled(Box)`
10
+ position: absolute;
11
+ top: 0;
12
+ left: 0;
13
+ width: 100%;
14
+ height: 100%;
15
+ `
16
+
17
+ const ReadOnlyContainer = styled(Flex)`
18
+ margin-top: 6rem;
19
+ background-color: var(--card-bg-color);
20
+ position: relative;
21
+ width: 100%;
22
+ `
23
+
24
+ const ColorPicker = ({
25
+ width,
26
+ rgb,
27
+ hex,
28
+ hsv,
29
+ hsl,
30
+ onChange,
31
+ onUnset,
32
+ disableAlpha,
33
+ renderers,
34
+ readOnly,
35
+ }) => {
36
+ return (
37
+ <div style={{width}}>
38
+ <Card padding={1} border radius={1}>
39
+ <Stack space={2}>
40
+ {!readOnly && (
41
+ <>
42
+ <Card overflow="hidden" style={{position: 'relative', height: '5em'}}>
43
+ <Saturation is="Saturation" onChange={onChange} hsl={hsl} hsv={hsv} />
44
+ </Card>
45
+
46
+ <Card
47
+ shadow={1}
48
+ radius={3}
49
+ overflow="hidden"
50
+ style={{position: 'relative', height: '10px'}}
51
+ >
52
+ <Hue is="Hue" hsl={hsl} onChange={!readOnly && onChange} />
53
+ </Card>
54
+
55
+ {!disableAlpha && (
56
+ <Card
57
+ shadow={1}
58
+ radius={3}
59
+ overflow="hidden"
60
+ style={{position: 'relative', height: '10px'}}
61
+ >
62
+ <Alpha is="Alpha" rgb={rgb} hsl={hsl} renderers={renderers} onChange={onChange} />
63
+ </Card>
64
+ )}
65
+ </>
66
+ )}
67
+ <Flex>
68
+ <Card
69
+ flex={1}
70
+ radius={2}
71
+ overflow="hidden"
72
+ style={{position: 'relative', minWidth: '4em'}}
73
+ >
74
+ <Checkboard />
75
+ <ColorBox style={{backgroundColor: `rgba(${rgb.r},${rgb.g},${rgb.b},${rgb.a})`}} />
76
+
77
+ {readOnly && (
78
+ <ReadOnlyContainer
79
+ padding={2}
80
+ paddingBottom={1}
81
+ sizing="border"
82
+ justify="space-between"
83
+ >
84
+ <Stack space={3} marginTop={1}>
85
+ <Text size={3} weight="bold">
86
+ {hex}
87
+ </Text>
88
+
89
+ <Inline space={3}>
90
+ <Text size={1}>
91
+ <strong>RGB: </strong>
92
+ {rgb.r} {rgb.g} {rgb.b}
93
+ </Text>
94
+ <Text size={1}>
95
+ <strong>HSL: </strong> {Math.round(hsl.h)} {Math.round(hsl.s)}%{' '}
96
+ {Math.round(hsl.l)}
97
+ </Text>
98
+ </Inline>
99
+ </Stack>
100
+ </ReadOnlyContainer>
101
+ )}
102
+ </Card>
103
+
104
+ {!readOnly && (
105
+ <Flex align="flex-start" marginLeft={2}>
106
+ <Box style={{width: 200}}>
107
+ <ColorPickerFields
108
+ rgb={rgb}
109
+ hsl={hsl}
110
+ hex={hex}
111
+ onChange={onChange}
112
+ disableAlpha={disableAlpha}
113
+ />
114
+ </Box>
115
+ <Box marginLeft={2}>
116
+ <Button onClick={onUnset} title="Delete color" icon={TrashIcon} tone="critical" />
117
+ </Box>
118
+ </Flex>
119
+ )}
120
+ </Flex>
121
+ </Stack>
122
+ </Card>
123
+ </div>
124
+ )
125
+ }
126
+
127
+ ColorPicker.propTypes = {
128
+ width: PropTypes.string,
129
+ hex: PropTypes.string,
130
+ hsl: PropTypes.object,
131
+ hsv: PropTypes.object,
132
+ rgb: PropTypes.object,
133
+ onChange: PropTypes.func,
134
+ disableAlpha: PropTypes.bool,
135
+ readOnly: PropTypes.bool,
136
+ renderers: PropTypes.func,
137
+ onUnset: PropTypes.func,
138
+ }
139
+
140
+ ColorPicker.defaultProps = {
141
+ disableAlpha: false,
142
+ }
143
+
144
+ export default ColorWrap(ColorPicker)
@@ -0,0 +1,128 @@
1
+ import React from 'react'
2
+ import * as color from 'react-color/lib/helpers/color'
3
+ import {EditableInput} from 'react-color/lib/components/common'
4
+ import {Box, Flex, useTheme} from '@sanity/ui'
5
+
6
+ export const ColorPickerFields = ({onChange, rgb, hsl, hex, disableAlpha}) => {
7
+ const {sanity} = useTheme()
8
+
9
+ const inputStyles = {
10
+ input: {
11
+ width: '80%',
12
+ padding: '4px 10% 3px',
13
+ border: 'none',
14
+ boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,
15
+ color: sanity.color.input.default.enabled.fg,
16
+ backgroundColor: sanity.color.input.default.enabled.bg,
17
+ fontSize: sanity.fonts.text.sizes[0].fontSize,
18
+ textAlign: 'center',
19
+ },
20
+ label: {
21
+ display: 'block',
22
+ textAlign: 'center',
23
+ fontSize: sanity.fonts.label.sizes[0].fontSize,
24
+ color: sanity.color.base.fg,
25
+ paddingTop: '3px',
26
+ paddingBottom: '4px',
27
+ textTransform: 'capitalize',
28
+ },
29
+ }
30
+
31
+ const handleChange = (data, e) => {
32
+ if (data.hex && color.isValidHex(data.hex)) {
33
+ onChange(
34
+ {
35
+ hex: data.hex,
36
+ source: 'hex',
37
+ },
38
+ e
39
+ )
40
+ } else if (data.r || data.g || data.b) {
41
+ onChange(
42
+ {
43
+ r: data.r || rgb.r,
44
+ g: data.g || rgb.g,
45
+ b: data.b || rgb.b,
46
+ a: rgb.a,
47
+ source: 'rgb',
48
+ },
49
+ e
50
+ )
51
+ } else if (data.a) {
52
+ if (data.a < 0) {
53
+ data.a = 0
54
+ } else if (data.a > 100) {
55
+ data.a = 100
56
+ }
57
+
58
+ data.a /= 100
59
+ onChange(
60
+ {
61
+ h: hsl.h,
62
+ s: hsl.s,
63
+ l: hsl.l,
64
+ a: data.a,
65
+ source: 'rgb',
66
+ },
67
+ e
68
+ )
69
+ }
70
+ }
71
+
72
+ return (
73
+ <Flex>
74
+ <Box flex={2} marginRight={1}>
75
+ <EditableInput
76
+ style={inputStyles}
77
+ label="hex"
78
+ value={hex.replace('#', '')}
79
+ onChange={handleChange}
80
+ />
81
+ </Box>
82
+ <Box flex={1} marginRight={1}>
83
+ <EditableInput
84
+ style={inputStyles}
85
+ label="r"
86
+ value={rgb.r}
87
+ onChange={handleChange}
88
+ dragLabel="true"
89
+ dragMax="255"
90
+ />
91
+ </Box>
92
+ <Box flex={1} marginRight={1}>
93
+ <EditableInput
94
+ style={inputStyles}
95
+ label="g"
96
+ value={rgb.g}
97
+ onChange={handleChange}
98
+ dragLabel="true"
99
+ dragMax="255"
100
+ />
101
+ </Box>
102
+ <Box flex={1} marginRight={1}>
103
+ <EditableInput
104
+ style={inputStyles}
105
+ label="b"
106
+ value={rgb.b}
107
+ onChange={handleChange}
108
+ dragLabel="true"
109
+ dragMax="255"
110
+ />
111
+ </Box>
112
+ {!disableAlpha && (
113
+ <Box flex={1}>
114
+ <EditableInput
115
+ style={inputStyles}
116
+ label="a"
117
+ value={Math.round(rgb.a * 100)}
118
+ onChange={handleChange}
119
+ dragLabel="true"
120
+ dragMax="100"
121
+ />
122
+ </Box>
123
+ )}
124
+ </Flex>
125
+ )
126
+ }
127
+
128
+ export default ColorPickerFields
@@ -0,0 +1,70 @@
1
+ /* eslint-disable react/display-name */
2
+ import React from 'react'
3
+ import ColorInput from '../ColorInput'
4
+
5
+ const round = (val) => Math.round(val * 100)
6
+
7
+ export default {
8
+ name: 'color',
9
+ type: 'object',
10
+ title: 'Color',
11
+ inputComponent: ColorInput,
12
+ fields: [
13
+ {
14
+ title: 'Hex',
15
+ name: 'hex',
16
+ type: 'string',
17
+ },
18
+ {
19
+ title: 'Alpha',
20
+ name: 'alpha',
21
+ type: 'number',
22
+ },
23
+ {
24
+ title: 'Hue Saturation Lightness',
25
+ name: 'hsl',
26
+ type: 'hslaColor',
27
+ },
28
+ {
29
+ title: 'Hue Saturation Value',
30
+ name: 'hsv',
31
+ type: 'hsvaColor',
32
+ },
33
+ {
34
+ title: 'Red Green Blue (rgb)',
35
+ name: 'rgb',
36
+ type: 'rgbaColor',
37
+ },
38
+ ],
39
+ preview: {
40
+ select: {
41
+ title: 'hex',
42
+ alpha: 'alpha',
43
+ hex: 'hex',
44
+ hsl: 'hsl',
45
+ },
46
+ prepare({title, hex, hsl, alpha}) {
47
+ let subtitle = hex || 'No color set'
48
+ if (hsl) {
49
+ subtitle = `H:${round(hsl.l)} S:${round(hsl.l)} L:${round(hsl.l)} A:${round(alpha)}`
50
+ }
51
+ return {
52
+ title: title,
53
+ subtitle: subtitle,
54
+ media: () => (
55
+ <div
56
+ style={{
57
+ backgroundColor: hex || '#000',
58
+ opacity: alpha || 1,
59
+ position: 'absolute',
60
+ height: '100%',
61
+ width: '100%',
62
+ top: '0',
63
+ left: '0',
64
+ }}
65
+ />
66
+ ),
67
+ }
68
+ },
69
+ },
70
+ }
@@ -0,0 +1,11 @@
1
+ export default {
2
+ title: 'Hue Saturation Lightness',
3
+ name: 'hslaColor',
4
+ type: 'object',
5
+ fields: [
6
+ {name: 'h', type: 'number', title: 'Hue'},
7
+ {name: 's', type: 'number', title: 'Saturation'},
8
+ {name: 'l', type: 'number', title: 'Lightness'},
9
+ {name: 'a', type: 'number', title: 'Alpha'},
10
+ ],
11
+ }
@@ -0,0 +1,11 @@
1
+ export default {
2
+ title: 'Hue Saturation Value',
3
+ name: 'hsvaColor',
4
+ type: 'object',
5
+ fields: [
6
+ {name: 'h', type: 'number', title: 'Hue'},
7
+ {name: 's', type: 'number', title: 'Saturation'},
8
+ {name: 'v', type: 'number', title: 'Value'},
9
+ {name: 'a', type: 'number', title: 'Alpha'},
10
+ ],
11
+ }
@@ -0,0 +1,11 @@
1
+ export default {
2
+ title: 'Red Green Blue (rgb)',
3
+ name: 'rgbaColor',
4
+ type: 'object',
5
+ fields: [
6
+ {name: 'r', type: 'number', title: 'Red'},
7
+ {name: 'g', type: 'number', title: 'Green'},
8
+ {name: 'b', type: 'number', title: 'Blue'},
9
+ {name: 'a', type: 'number', title: 'Alpha'},
10
+ ],
11
+ }