@lowdefy/blocks-color-selectors 4.0.0-alpha.29 → 4.0.0-alpha.30

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.
@@ -0,0 +1,69 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React, { useCallback, useRef, useState } from 'react';
16
+ import { HexColorPicker, HexColorInput } from 'react-colorful';
17
+ import classNames from 'classnames';
18
+ import useClickOutside from './useClickOutside.js';
19
+ const DEFAULT_COLOR = '#000000';
20
+ export const ColorPicker = ({ className , disabled , hideInput , onChange , size , undefinedColor , value , })=>{
21
+ const popover = useRef();
22
+ const [isOpen, toggle] = useState(false);
23
+ const [color, setColor] = useState(value || undefinedColor || DEFAULT_COLOR);
24
+ const close = useCallback((newColor)=>{
25
+ toggle(false);
26
+ onChange(newColor);
27
+ }, []);
28
+ useClickOutside(popover, close, color);
29
+ return /*#__PURE__*/ React.createElement("div", {
30
+ className: classNames({
31
+ 'color-picker': true,
32
+ [className]: true
33
+ })
34
+ }, /*#__PURE__*/ React.createElement("div", {
35
+ className: classNames({
36
+ 'color-picker-swatch': true,
37
+ 'color-picker-swatch-sm': size === 'small',
38
+ 'color-picker-swatch-lg': size === 'large',
39
+ 'color-picker-swatch-disabled': disabled
40
+ }),
41
+ style: {
42
+ backgroundColor: color
43
+ },
44
+ onClick: ()=>!disabled && toggle(true)
45
+ }), !hideInput && /*#__PURE__*/ React.createElement(HexColorInput, {
46
+ className: classNames({
47
+ 'color-picker-input': true,
48
+ 'color-picker-input-sm ': size === 'small',
49
+ 'color-picker-input-lg': size === 'large',
50
+ 'ant-input': true,
51
+ 'ant-input-sm': size === 'small',
52
+ 'ant-input-lg': size === 'large'
53
+ }),
54
+ color: color,
55
+ onChange: (newColor)=>{
56
+ setColor(newColor);
57
+ onChange(newColor);
58
+ },
59
+ prefixed: true,
60
+ disabled: disabled
61
+ }), isOpen && /*#__PURE__*/ React.createElement("div", {
62
+ className: "color-picker-popover",
63
+ ref: popover
64
+ }, /*#__PURE__*/ React.createElement(HexColorPicker, {
65
+ color: color,
66
+ onChange: setColor
67
+ })));
68
+ };
69
+ export default ColorPicker;
@@ -0,0 +1,68 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React from 'react';
16
+ import { blockDefaultProps } from '@lowdefy/block-utils';
17
+ import Label from '@lowdefy/blocks-antd/blocks/Label/Label.js';
18
+ import ColorPicker from './ColorPicker.js';
19
+ const ColorSelector = ({ blockId , components , events , loading , methods , properties , required , validation , value , })=>{
20
+ return /*#__PURE__*/ React.createElement(Label, {
21
+ blockId: blockId,
22
+ components: components,
23
+ events: events,
24
+ methods: methods,
25
+ properties: {
26
+ title: properties.title,
27
+ size: properties.size,
28
+ ...properties.label
29
+ },
30
+ required: required,
31
+ validation: validation,
32
+ content: {
33
+ content: ()=>/*#__PURE__*/ React.createElement(ColorPicker, {
34
+ id: `${blockId}_input`,
35
+ className: methods.makeCssClass([
36
+ {
37
+ marginBottom: '0px !important'
38
+ },
39
+ properties.inputStyle,
40
+ ]),
41
+ onChange: (newColor)=>{
42
+ methods.setValue(newColor);
43
+ methods.triggerEvent({
44
+ name: 'onChange'
45
+ });
46
+ },
47
+ size: properties.size,
48
+ undefinedColor: properties.undefinedColor,
49
+ value: value,
50
+ hideInput: properties.hideInput,
51
+ disabled: properties.disabled || loading,
52
+ methods: methods
53
+ })
54
+ }
55
+ });
56
+ };
57
+ ColorSelector.defaultProps = blockDefaultProps;
58
+ ColorSelector.meta = {
59
+ valueType: 'string',
60
+ category: 'input',
61
+ icons: [
62
+ ...Label.meta.icons
63
+ ],
64
+ styles: [
65
+ 'blocks/ColorSelector/style.less'
66
+ ]
67
+ };
68
+ export default ColorSelector;
@@ -0,0 +1,106 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "type": "object",
5
+ "properties": {
6
+ "title": {
7
+ "type": "string",
8
+ "description": "Title to describe the input component, if no title is specified the block id is displayed."
9
+ },
10
+ "undefinedColor": {
11
+ "type": "string",
12
+ "default": "#000000",
13
+ "description": "Default color to display if input value is null.",
14
+ "docs": {
15
+ "displayType": "color"
16
+ }
17
+ },
18
+ "inputStyle": {
19
+ "type": "object",
20
+ "description": "Css style to applied to input.",
21
+ "docs": {
22
+ "displayType": "yaml"
23
+ }
24
+ },
25
+ "disabled": {
26
+ "type": "boolean",
27
+ "default": false,
28
+ "description": "If true, the input is disabled."
29
+ },
30
+ "hideInput": {
31
+ "type": "boolean",
32
+ "default": false,
33
+ "description": "If true, the input is hidden."
34
+ },
35
+ "label": {
36
+ "type": "object",
37
+ "description": "Label properties.",
38
+ "additionalProperties": false,
39
+ "properties": {
40
+ "align": {
41
+ "type": "string",
42
+ "enum": ["left", "right"],
43
+ "default": "left",
44
+ "description": "Align label left or right when inline."
45
+ },
46
+ "colon": {
47
+ "type": "boolean",
48
+ "default": true,
49
+ "description": "Append label with colon."
50
+ },
51
+ "extra": {
52
+ "type": "string",
53
+ "description": "Extra text to display beneath the content."
54
+ },
55
+ "title": {
56
+ "type": "string",
57
+ "description": "Label title."
58
+ },
59
+ "span": {
60
+ "type": "number",
61
+ "description": "Label inline span."
62
+ },
63
+ "disabled": {
64
+ "type": "boolean",
65
+ "default": false,
66
+ "description": "Hide input label."
67
+ },
68
+ "hasFeedback": {
69
+ "type": "boolean",
70
+ "default": true,
71
+ "description": "Display feedback extra from validation, this does not disable validation."
72
+ },
73
+ "inline": {
74
+ "type": "boolean",
75
+ "default": false,
76
+ "description": "Render input and label inline."
77
+ },
78
+ "extraStyle": {
79
+ "type": "object",
80
+ "description": "Css style to applied to label extra.",
81
+ "docs": {
82
+ "displayType": "yaml"
83
+ }
84
+ },
85
+ "feedbackStyle": {
86
+ "type": "object",
87
+ "description": "Css style to applied to label feedback.",
88
+ "docs": {
89
+ "displayType": "yaml"
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ },
96
+ "events": {
97
+ "type": "object",
98
+ "additionalProperties": false,
99
+ "properties": {
100
+ "onChange": {
101
+ "type": "array",
102
+ "description": "Trigger actions when color is picked."
103
+ }
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,73 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ @import '@lowdefy/blocks-antd/blocks/Label/style.less';
18
+ @import '@lowdefy/blocks-antd/blocks/TextInput/style.less';
19
+
20
+ .color-picker {
21
+ position: relative;
22
+ display: flex;
23
+ }
24
+
25
+ .color-picker-swatch {
26
+ flex: 0 0 auto;
27
+ width: 34px;
28
+ height: 34px;
29
+ border-radius: 2px;
30
+ border: 3px solid #fff;
31
+ box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
32
+ cursor: pointer;
33
+ }
34
+
35
+ .color-picker-swatch-disabled {
36
+ cursor: disabled;
37
+ }
38
+
39
+ .color-picker-swatch-sm {
40
+ width: 24px;
41
+ height: 24px;
42
+ }
43
+
44
+ .color-picker-swatch-lg {
45
+ width: 40px;
46
+ height: 40px;
47
+ }
48
+
49
+ .small .react-colorful {
50
+ width: 120px;
51
+ height: 120px;
52
+ }
53
+
54
+ .color-picker-popover {
55
+ position: absolute;
56
+ top: calc(100% + 2px);
57
+ left: 0;
58
+ border-radius: 3px;
59
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
60
+ z-index: 1000;
61
+ }
62
+
63
+ .color-picker-input {
64
+ margin-left: 8px;
65
+ }
66
+
67
+ .color-picker-input-sm {
68
+ margin-left: 0px;
69
+ }
70
+
71
+ .color-picker-input-lg {
72
+ margin-left: 12px;
73
+ }
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { useEffect } from 'react';
16
+ // Improved version of https://usehooks.com/useOnClickOutside/
17
+ const useClickOutside = (ref, handler, value)=>{
18
+ useEffect(()=>{
19
+ let startedInside = false;
20
+ let startedWhenMounted = false;
21
+ const listener = (event)=>{
22
+ // Do nothing if `mousedown` or `touchstart` started inside ref element
23
+ if (startedInside || !startedWhenMounted) return;
24
+ // Do nothing if clicking ref's element or descendent elements
25
+ if (!ref.current || ref.current.contains(event.target)) return;
26
+ handler(value, event);
27
+ };
28
+ const validateEventStart = (event)=>{
29
+ startedWhenMounted = ref.current;
30
+ startedInside = ref.current && ref.current.contains(event.target);
31
+ };
32
+ document.addEventListener('mousedown', validateEventStart);
33
+ document.addEventListener('touchstart', validateEventStart);
34
+ document.addEventListener('click', listener);
35
+ return ()=>{
36
+ document.removeEventListener('mousedown', validateEventStart);
37
+ document.removeEventListener('touchstart', validateEventStart);
38
+ document.removeEventListener('click', listener);
39
+ };
40
+ }, [
41
+ ref,
42
+ handler,
43
+ value
44
+ ]);
45
+ };
46
+ export default useClickOutside;
package/dist/blocks.js ADDED
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export { default as ColorSelector } from './blocks/ColorSelector/ColorSelector.js';
package/dist/types.js ADDED
@@ -0,0 +1,29 @@
1
+ /* eslint-disable import/namespace */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import * as blocks from './blocks.js';
16
+ const icons = {};
17
+ const styles = {};
18
+ Object.keys(blocks).forEach((block)=>{
19
+ icons[block] = blocks[block].meta.icons || [];
20
+ styles[block] = blocks[block].meta.styles || [];
21
+ });
22
+ export default {
23
+ blocks: Object.keys(blocks),
24
+ icons,
25
+ styles: {
26
+ default: [],
27
+ ...styles
28
+ }
29
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/blocks-color-selectors",
3
- "version": "4.0.0-alpha.29",
3
+ "version": "4.0.0-alpha.30",
4
4
  "license": "Apache-2.0",
5
5
  "description": "A Lowdefy color selector blocks based on react-color.",
6
6
  "homepage": "https://lowdefy.com",
@@ -50,8 +50,8 @@
50
50
  "test": "jest --coverage"
51
51
  },
52
52
  "dependencies": {
53
- "@lowdefy/block-utils": "4.0.0-alpha.29",
54
- "@lowdefy/blocks-antd": "4.0.0-alpha.29",
53
+ "@lowdefy/block-utils": "4.0.0-alpha.30",
54
+ "@lowdefy/blocks-antd": "4.0.0-alpha.30",
55
55
  "classnames": "2.3.1",
56
56
  "react": "18.1.0",
57
57
  "react-colorful": "5.5.1",
@@ -59,8 +59,8 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "@emotion/jest": "11.9.1",
62
- "@lowdefy/block-dev": "4.0.0-alpha.29",
63
- "@lowdefy/jest-yaml-transform": "4.0.0-alpha.29",
62
+ "@lowdefy/block-dev": "4.0.0-alpha.30",
63
+ "@lowdefy/jest-yaml-transform": "4.0.0-alpha.30",
64
64
  "@swc/cli": "0.1.57",
65
65
  "@swc/core": "1.2.194",
66
66
  "@swc/jest": "0.2.21",
@@ -76,5 +76,5 @@
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  },
79
- "gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
79
+ "gitHead": "c30cc4e28e221d9b73385cca8d339397d60da0e1"
80
80
  }