@synerise/ds-color-picker 0.1.7 → 0.1.8

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/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.1.8](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.1.7...@synerise/ds-color-picker@0.1.8) (2023-01-30)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **color-picker:** bugs ([9702cad](https://github.com/Synerise/synerise-design/commit/9702cada1d33b94275681b905cba291684cf7732))
12
+ * **color-picker:** main wrapper for the color-picker component ([6c3ad7e](https://github.com/Synerise/synerise-design/commit/6c3ad7ea4d1b2a4a089a0494126a2f12962588df))
13
+ * **color-picker:** max-width of dropdown overlay ([42d2f60](https://github.com/Synerise/synerise-design/commit/42d2f60a7be3f63d486c8f27029f5602650fe1c7))
14
+ * **color-picker:** utils for colorPicker component ([d78395d](https://github.com/Synerise/synerise-design/commit/d78395d29b366f2a3edf06edc83351865e7bb875))
15
+
16
+
17
+
18
+
19
+
6
20
  ## [0.1.7](https://github.com/Synerise/synerise-design/compare/@synerise/ds-color-picker@0.1.6...@synerise/ds-color-picker@0.1.7) (2023-01-12)
7
21
 
8
22
  **Note:** Version bump only for package @synerise/ds-color-picker
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { ColorPickerProps } from './ColorPicker.types';
3
- export declare function ColorPicker({ value, onChange, colors, onSaveColors, infix, placeholder, inputProps, maxSavedColors, tooltipText, isShownSavedColors, size, errorText, description, }: ColorPickerProps): JSX.Element;
3
+ declare const ColorPicker: ({ maxWidth, value, onChange, colors, onSaveColors, infix, placeholder, inputProps, maxSavedColors, tooltipText, isShownSavedColors, size, errorText, description, }: ColorPickerProps) => JSX.Element;
4
4
  export default ColorPicker;
@@ -9,9 +9,14 @@ import * as copy from 'copy-to-clipboard';
9
9
  import Tooltip from '@synerise/ds-tooltip';
10
10
  import Dropdown from '@synerise/ds-dropdown';
11
11
  import { useOnClickOutside } from '@synerise/ds-utils';
12
+ import { isValidHexColor, convert3DigitHexTo6Digit, filterAlphanumeric } from './utils';
12
13
  import ColorPickerStyles from './ColorPicker.styles';
13
- export function ColorPicker(_ref) {
14
- var _ref$value = _ref.value,
14
+ var hash = '#';
15
+ var DEFAULT_MAX_WIDTH_PICKER = 228;
16
+
17
+ var ColorPicker = function ColorPicker(_ref) {
18
+ var maxWidth = _ref.maxWidth,
19
+ _ref$value = _ref.value,
15
20
  value = _ref$value === void 0 ? '#ffffff' : _ref$value,
16
21
  onChange = _ref.onChange,
17
22
  _ref$colors = _ref.colors,
@@ -36,15 +41,34 @@ export function ColorPicker(_ref) {
36
41
  color = _React$useState[0],
37
42
  setColor = _React$useState[1];
38
43
 
39
- var _React$useState2 = React.useState(-1),
40
- pressed = _React$useState2[0],
41
- setPressed = _React$useState2[1];
44
+ var _React$useState2 = React.useState(value),
45
+ validHexColor = _React$useState2[0],
46
+ setValidHexColor = _React$useState2[1];
47
+
48
+ var _React$useState3 = React.useState(-1),
49
+ pressed = _React$useState3[0],
50
+ setPressed = _React$useState3[1];
51
+
52
+ var _React$useState4 = React.useState(false),
53
+ dropdownVisible = _React$useState4[0],
54
+ setDropdownVisible = _React$useState4[1];
42
55
 
43
- var onChangeColor = function onChangeColor(colorValue) {
56
+ var _React$useState5 = React.useState(colors),
57
+ savedColors = _React$useState5[0],
58
+ setSavedColors = _React$useState5[1];
59
+
60
+ var onChangeColor = React.useCallback(function (colorValue) {
44
61
  setColor(colorValue);
45
- onChange && onChange(colorValue);
46
- };
47
62
 
63
+ if (isValidHexColor(colorValue)) {
64
+ var c = convert3DigitHexTo6Digit(colorValue);
65
+ setValidHexColor(c);
66
+ onChange && onChange(c);
67
+ }
68
+ }, [onChange]);
69
+ var onBlurHandler = React.useCallback(function () {
70
+ setColor(validHexColor);
71
+ }, [validHexColor]);
48
72
  var heightOfDropdown = React.useCallback(function () {
49
73
  if (errorText || description) {
50
74
  if (errorText && description) {
@@ -56,22 +80,11 @@ export function ColorPicker(_ref) {
56
80
 
57
81
  return 4;
58
82
  }, [errorText, description]);
59
-
60
- var _React$useState3 = React.useState(false),
61
- dropdownVisible = _React$useState3[0],
62
- setDropdownVisible = _React$useState3[1];
63
-
64
83
  var ref = React.useRef(null);
65
84
  useOnClickOutside(ref, function () {
66
85
  setDropdownVisible(false);
67
86
  });
68
87
 
69
- var _React$useState4 = React.useState(colors),
70
- savedColors = _React$useState4[0],
71
- setSavedColors = _React$useState4[1];
72
-
73
- var hash = '#';
74
-
75
88
  var saveColor = function saveColor() {
76
89
  setSavedColors(function (ar) {
77
90
  var colorsArray = (color ? [color].concat(ar) : ar).slice(0, maxSavedColors);
@@ -118,22 +131,25 @@ export function ColorPicker(_ref) {
118
131
  ref: ref,
119
132
  size: size
120
133
  }, /*#__PURE__*/React.createElement(ReactColorful, {
121
- color: color,
134
+ color: validHexColor,
122
135
  onChange: onChangeColor
123
136
  }), /*#__PURE__*/React.createElement(ColorPickerStyles.PrefixTag, {
124
- height: isShownSavedColors
137
+ height: isShownSavedColors,
138
+ size: size
125
139
  }, /*#__PURE__*/React.createElement(Tag, {
126
140
  shape: TagShape.SINGLE_CHARACTER_SQUARE,
127
- color: color,
141
+ color: validHexColor,
128
142
  disabled: false
129
143
  })), /*#__PURE__*/React.createElement(ColorPickerStyles.SubContainer, {
130
144
  savedColors: isShownSavedColors
131
145
  }, /*#__PURE__*/React.createElement(ColorPickerStyles.ColorPickerInput, {
132
- value: color.substr(1),
146
+ value: filterAlphanumeric(color),
133
147
  prefixel: /*#__PURE__*/React.createElement(ColorPickerStyles.PreffixWrapper, null, "#"),
134
148
  onChange: function onChange(ev) {
135
- return setColor(hash + ev.target.value);
149
+ var hexValue = hash + filterAlphanumeric(ev.target.value);
150
+ onChangeColor(hexValue);
136
151
  },
152
+ onBlur: onBlurHandler,
137
153
  placeholder: placeholder,
138
154
  icon1: /*#__PURE__*/React.createElement(ColorPickerStyles.CopyIcon, {
139
155
  onClick: function onClick() {
@@ -141,9 +157,12 @@ export function ColorPicker(_ref) {
141
157
  },
142
158
  component: /*#__PURE__*/React.createElement(CopyClipboardM, null)
143
159
  }),
144
- icon1Tooltip: /*#__PURE__*/React.createElement("span", null, tooltipText)
160
+ icon1Tooltip: /*#__PURE__*/React.createElement("span", null, tooltipText || 'Copy to clipboard')
145
161
  }), isShownSavedColors && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Divider, null), swatchSection)));
146
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown, {
162
+ return /*#__PURE__*/React.createElement(React.Fragment, null, maxWidth && maxWidth >= DEFAULT_MAX_WIDTH_PICKER && /*#__PURE__*/React.createElement(ColorPickerStyles.ColorPickerModalStyle, {
163
+ maxWidth: maxWidth
164
+ }), /*#__PURE__*/React.createElement(Dropdown, {
165
+ overlayClassName: "color-picker-overlay",
147
166
  align: {
148
167
  offset: [0, heightOfDropdown()]
149
168
  },
@@ -153,19 +172,22 @@ export function ColorPicker(_ref) {
153
172
  }, /*#__PURE__*/React.createElement(ColorPickerStyles.ColorPickerSelect, _extends({
154
173
  prefix: /*#__PURE__*/React.createElement(ColorPickerStyles.ColorTag, {
155
174
  shape: TagShape.SINGLE_CHARACTER_ROUND,
156
- color: color,
157
- disabled: false
175
+ color: validHexColor,
176
+ disabled: false,
177
+ onClick: function onClick() {
178
+ return setDropdownVisible(!dropdownVisible);
179
+ }
158
180
  }),
159
181
  onChange: function onChange(ev) {
160
- return setColor(ev.target.value);
182
+ var hexValue = hash + filterAlphanumeric(ev.target.value);
183
+ onChangeColor(hexValue);
161
184
  },
185
+ onBlur: onBlurHandler,
162
186
  placeholder: placeholder,
163
- onClick: function onClick() {
164
- return setDropdownVisible(!dropdownVisible);
165
- },
166
187
  value: color,
167
188
  description: description,
168
189
  errorText: errorText
169
190
  }, inputProps))));
170
- }
191
+ };
192
+
171
193
  export default ColorPicker;
@@ -38,10 +38,14 @@ export declare const ColorPickerSelect: import("styled-components").StyledCompon
38
38
  }), any, {}, never>;
39
39
  export declare const PrefixTag: import("styled-components").StyledComponent<"div", any, {
40
40
  height?: boolean | undefined;
41
+ size?: "S" | "M" | "L" | undefined;
41
42
  }, never>;
42
43
  export declare const SwatchSectionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
43
44
  export declare const PreffixWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
44
45
  export declare const ValueWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
46
+ export declare const ColorPickerModalStyle: import("styled-components").GlobalStyleComponent<{
47
+ maxWidth: number;
48
+ }, import("styled-components").DefaultTheme>;
45
49
  declare const _default: {
46
50
  Container: import("styled-components").StyledComponent<"div", any, {
47
51
  size?: "S" | "M" | "L" | undefined;
@@ -52,6 +56,7 @@ declare const _default: {
52
56
  ColorTag: import("styled-components").StyledComponent<import("react").FC<import("@synerise/ds-tags/dist/Tag/Tag.types").Props>, any, {}, never>;
53
57
  PrefixTag: import("styled-components").StyledComponent<"div", any, {
54
58
  height?: boolean | undefined;
59
+ size?: "S" | "M" | "L" | undefined;
55
60
  }, never>;
56
61
  AddColorButton: import("styled-components").StyledComponent<typeof Button, any, {}, never>;
57
62
  SwatchSectionWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -91,5 +96,8 @@ declare const _default: {
91
96
  })> & {
92
97
  displayName: string;
93
98
  }), any, {}, never>;
99
+ ColorPickerModalStyle: import("styled-components").GlobalStyleComponent<{
100
+ maxWidth: number;
101
+ }, import("styled-components").DefaultTheme>;
94
102
  };
95
103
  export default _default;
@@ -1,4 +1,8 @@
1
- import styled from 'styled-components'; // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
1
+ var _templateObject;
2
+
3
+ function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
4
+
5
+ import styled, { createGlobalStyle } from 'styled-components'; // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
2
6
  // @ts-ignore
3
7
 
4
8
  import { TagsStyles, Tag } from '@synerise/ds-tags';
@@ -14,11 +18,11 @@ export var TagDot = styled.div.withConfig({
14
18
  }, function (props) {
15
19
  return props.theme.palette.white;
16
20
  });
17
- var SIZE_DEFAULT = 167;
21
+ var SIZE_DEFAULT = 168;
18
22
  var Container = styled.div.withConfig({
19
23
  displayName: "ColorPickerstyles__Container",
20
24
  componentId: "sc-1iu8b6j-1"
21
- })(["@media (min-width:200px){min-width:200px;margin:-8px;background-color:", ";}.react-colorful__last-control{margin:24px 56px 8px 17px;border-radius:4px;height:8px;}.react-colorful__saturation{border-bottom:0px;border-radius:4px 4px 0 0;height:96px;.react-colorful__interactive{height:96px;}}&&& .ds-tag{width:16px;height:16px;margin:0px 4px 8px;border:1px solid ", ";&:hover{", "{display:flex;}}}.react-colorful__pointer{width:16px;height:16px;}.react-colorful{width:268px;max-width:268px;height:", "px;}.react-colorful__hue-pointer{border:1px solid ", ";box-shadow:none !important;.react-colorful__pointer-fill{background-color:", " !important;}}.ant-divider-horizontal{margin:16px 0px;}", "{margin-bottom:-8px;}"], function (props) {
25
+ })(["width:100%;@media (min-width:200px){min-width:200px;margin:-8px;background-color:", ";}.react-colorful__last-control{margin:24px 56px 8px 17px;border-radius:4px;height:8px;}.react-colorful__saturation{border-bottom:0px;border-radius:4px 4px 0 0;height:96px;.react-colorful__interactive{width:100%;height:100%;}}&&& .ds-tag{width:16px;height:16px;border:1px solid ", ";margin:0 0 0 4px;&:hover{", "{display:flex;}}}.react-colorful__pointer{width:16px;height:16px;}.react-colorful{width:100%;height:", "px;}.react-colorful__hue-pointer{border:1px solid ", ";box-shadow:none !important;.react-colorful__pointer-fill{background-color:", " !important;}}.ant-divider-horizontal{margin:16px 0px;}", "{margin-bottom:-8px;}"], function (props) {
22
26
  return props.theme.palette.white;
23
27
  }, function (props) {
24
28
  return props.theme.palette['grey-300'];
@@ -32,8 +36,8 @@ var Container = styled.div.withConfig({
32
36
  var SubContainer = styled.div.withConfig({
33
37
  displayName: "ColorPickerstyles__SubContainer",
34
38
  componentId: "sc-1iu8b6j-2"
35
- })(["padding:", ";"], function (props) {
36
- return props.savedColors ? '8px 16px 16px' : '8px 16px 0;';
39
+ })(["padding:8px 16px 16px;margin-bottom:", ";"], function (props) {
40
+ return props.savedColors ? "0" : "-16px";
37
41
  });
38
42
  export var ColorTag = styled(Tag).withConfig({
39
43
  displayName: "ColorPickerstyles__ColorTag",
@@ -44,7 +48,7 @@ export var ColorTag = styled(Tag).withConfig({
44
48
  export var AddColorButton = styled(Button).withConfig({
45
49
  displayName: "ColorPickerstyles__AddColorButton",
46
50
  componentId: "sc-1iu8b6j-4"
47
- })(["&&&.ant-btn{width:16px;height:16px;margin-right:2px;}"]);
51
+ })(["&&&.ant-btn{width:16px;height:16px;margin-right:0;}"]);
48
52
  export var CopyIcon = styled(Icon).withConfig({
49
53
  displayName: "ColorPickerstyles__CopyIcon",
50
54
  componentId: "sc-1iu8b6j-5"
@@ -60,12 +64,10 @@ export var ColorPickerSelect = styled(Input).withConfig({
60
64
  export var PrefixTag = styled.div.withConfig({
61
65
  displayName: "ColorPickerstyles__PrefixTag",
62
66
  componentId: "sc-1iu8b6j-8"
63
- })(["&&& .ds-tag{width:24px;height:24px;border:1px solid ", ";cursor:auto;&:hover:before{cursor:auto;filter:brightness(100%);}}position:absolute;right:", ";bottom:", ";z-index:2;cursor:auto;"], function (props) {
67
+ })(["&&& .ds-tag{margin:0;width:24px;height:24px;border:1px solid ", ";cursor:auto;&:hover:before{cursor:auto;filter:brightness(100%);}}position:absolute;right:16px;top:", "px;z-index:2;cursor:auto;"], function (props) {
64
68
  return props.theme.palette['grey-300'];
65
69
  }, function (props) {
66
- return props.height ? '12px' : '12px';
67
- }, function (props) {
68
- return props.height ? '97px' : '48px';
70
+ return (ColorPickerSize[props.size] || SIZE_DEFAULT) - 25;
69
71
  });
70
72
  export var SwatchSectionWrapper = styled.div.withConfig({
71
73
  displayName: "ColorPickerstyles__SwatchSectionWrapper",
@@ -74,11 +76,17 @@ export var SwatchSectionWrapper = styled.div.withConfig({
74
76
  export var PreffixWrapper = styled.div.withConfig({
75
77
  displayName: "ColorPickerstyles__PreffixWrapper",
76
78
  componentId: "sc-1iu8b6j-10"
77
- })(["padding:6px 12px;"]);
79
+ })(["margin:0px 12px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:", ";"], function (props) {
80
+ return props.theme.palette['grey-500'];
81
+ });
78
82
  export var ValueWrapper = styled.div.withConfig({
79
83
  displayName: "ColorPickerstyles__ValueWrapper",
80
84
  componentId: "sc-1iu8b6j-11"
81
85
  })(["display:flex;font-size:12px;"]);
86
+ export var ColorPickerModalStyle = createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n.color-picker-overlay {\n min-width: unset !important;\n max-width: ", "px; \n width: 100%;\n}"])), function (_ref) {
87
+ var maxWidth = _ref.maxWidth;
88
+ return maxWidth;
89
+ });
82
90
  export default {
83
91
  Container: Container,
84
92
  SubContainer: SubContainer,
@@ -91,5 +99,6 @@ export default {
91
99
  CopyIcon: CopyIcon,
92
100
  ColorPickerInput: ColorPickerInput,
93
101
  TagDot: TagDot,
94
- ColorPickerSelect: ColorPickerSelect
102
+ ColorPickerSelect: ColorPickerSelect,
103
+ ColorPickerModalStyle: ColorPickerModalStyle
95
104
  };
@@ -5,11 +5,12 @@ export declare type ColorHookType = {
5
5
  setColor: (color: string) => void;
6
6
  };
7
7
  export declare enum ColorPickerSize {
8
- 'S' = 135,
9
- 'M' = 167,
10
- 'L' = 199
8
+ 'S' = 136,
9
+ 'M' = 168,
10
+ 'L' = 200
11
11
  }
12
12
  export interface ColorPickerProps extends Partial<Pick<HTMLInputElement, 'placeholder'>> {
13
+ maxWidth?: number;
13
14
  value?: string;
14
15
  onChange?: (color: string) => void;
15
16
  colors?: string[];
@@ -1,7 +1,7 @@
1
1
  export var ColorPickerSize;
2
2
 
3
3
  (function (ColorPickerSize) {
4
- ColorPickerSize[ColorPickerSize["S"] = 135] = "S";
5
- ColorPickerSize[ColorPickerSize["M"] = 167] = "M";
6
- ColorPickerSize[ColorPickerSize["L"] = 199] = "L";
4
+ ColorPickerSize[ColorPickerSize["S"] = 136] = "S";
5
+ ColorPickerSize[ColorPickerSize["M"] = 168] = "M";
6
+ ColorPickerSize[ColorPickerSize["L"] = 200] = "L";
7
7
  })(ColorPickerSize || (ColorPickerSize = {}));
@@ -0,0 +1,3 @@
1
+ export declare const filterAlphanumeric: (colorValue: string) => string;
2
+ export declare const isValidHexColor: (hex: string) => boolean;
3
+ export declare const convert3DigitHexTo6Digit: (hexColor: string) => string;
package/dist/utils.js ADDED
@@ -0,0 +1,23 @@
1
+ var alphanumericRegex = /[^a-zA-Z0-9]+/g;
2
+ var hexColorRegex = /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/;
3
+ export var filterAlphanumeric = function filterAlphanumeric(colorValue) {
4
+ return colorValue.replace(alphanumericRegex, '');
5
+ };
6
+ export var isValidHexColor = function isValidHexColor(hex) {
7
+ return hexColorRegex.test(hex);
8
+ };
9
+ export var convert3DigitHexTo6Digit = function convert3DigitHexTo6Digit(hexColor) {
10
+ var alphaHexColor = filterAlphanumeric(hexColor);
11
+
12
+ if (alphaHexColor.length === 3) {
13
+ var newAlphaHexColor = ''; // eslint-disable-next-line no-plusplus
14
+
15
+ for (var i = 0; i < alphaHexColor.length; i++) {
16
+ newAlphaHexColor += alphaHexColor[i] + alphaHexColor[i];
17
+ }
18
+
19
+ return "#" + newAlphaHexColor;
20
+ }
21
+
22
+ return hexColor;
23
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-color-picker",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Color-Picker Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -45,5 +45,5 @@
45
45
  "@synerise/ds-core": "*",
46
46
  "react": ">=16.9.0 < 17.0.0"
47
47
  },
48
- "gitHead": "f7e3eb0af66bff4d1bdec91b30d2075cc0799567"
48
+ "gitHead": "09992e7b69930b5357e169418af91e29d1cba5ee"
49
49
  }