plain-design 1.0.0-beta.146 → 1.0.0-beta.148

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.
@@ -1,125 +1,146 @@
1
- import './color-panel.scss';
2
- import {designComponent, getComponentCls, iMouseEvent, reactive, useModel} from "@peryl/react-compose";
3
- import {ColorSvPanel} from "./sub/ColorSvPanel";
4
- import {ColorHueSlider} from "./sub/ColorHueSlider";
5
- import {ColorAlphaSlider} from "./sub/ColorAlphaSlider";
6
- import {PlainColor} from "./utils/PlainColor";
7
- import {useColorPanelEditor} from "./useColorPanelEditor";
8
- import {useColorPanelHistory} from "./useColorPanelHistory";
9
- import {ColorPanelPublicPropOptions} from "./utils/color-picker.utils";
10
-
11
-
12
- export const ColorPanel = designComponent({
13
- name: 'color-panel',
14
- props: {
15
- ...ColorPanelPublicPropOptions
16
- },
17
- emits: {
18
- onUpdateModelValue: (val: any) => true,
19
- onDblclickSvPanel: (e: iMouseEvent) => true,
20
- },
21
- inheritPropsType: HTMLDivElement,
22
- setup({ props, event: { emit } }) {
23
-
24
- const model = useModel(() => props.modelValue, emit.onUpdateModelValue, {
25
- onChange: (value) => {
26
- const prev = state.colorState;
27
- const colorState = utils.getState(value, prev);
28
- if (colorState !== prev) {
29
- state.colorState = colorState;
30
- }
31
- },
32
- });
33
-
34
- const utils = {
35
- getState: (value: string | null | undefined, prev?: iColorState): iColorState => {
36
- if (!prev) {
37
- return { color: new PlainColor(value || '#FFFFFF'), value };
38
- } else {
39
- if (prev.value == value) {
40
- return prev;
41
- } else {
42
- return { color: new PlainColor(value || '#FFFFFF'), value };
43
- }
44
- }
45
- },
46
- };
47
-
48
- const state = reactive({
49
- colorState: utils.getState(model.value)
50
- });
51
-
52
- const handler = {
53
- svChange: ({ value, saturation }: { value: number, saturation: number }) => {
54
- const color = state.colorState.color.useHsva({ v: value, s: saturation });
55
- state.colorState = { color, value: color.value };
56
- model.value = state.colorState.value!;
57
- },
58
- hueChange: (hue: number) => {
59
- const color = state.colorState.color.useHsva({ h: hue });
60
- state.colorState = { color, value: color.value };
61
- model.value = state.colorState.value!;
62
- },
63
- alphaChange: (alpha: number) => {
64
- const color = state.colorState.color.useHsva({ a: alpha / 100 });
65
- state.colorState = { color, value: color.value };
66
- model.value = state.colorState.value!;
67
- },
68
- };
69
-
70
- const editor = useColorPanelEditor({
71
- props,
72
- getColor: () => state.colorState.color,
73
- onChange: color => {
74
- state.colorState = { color, value: color.value };
75
- model.value = color.value;
76
- }
77
- });
78
-
79
- const history = useColorPanelHistory({
80
- onChange: color => {
81
- state.colorState = { color, value: color.value };
82
- model.value = color.value;
83
- }
84
- });
85
-
86
- return {
87
- render: () => (
88
- <div className={getComponentCls('color-panel')}>
89
- <div className="color-panel-card">
90
- <ColorSvPanel
91
- hue={state.colorState.color.h}
92
- modelValue={state.colorState.color.v}
93
- saturation={state.colorState.color.s}
94
- onChange={handler.svChange}
95
- onDblclick={emit.onDblclickSvPanel}
96
- disable={props.disableSvPanel}
97
- />
98
- <div className="color-panel-slider-bar">
99
- <div className="color-panel-slider-container">
100
- <ColorHueSlider
101
- modelValue={state.colorState.color.h}
102
- onChange={handler.hueChange}
103
- />
104
- <ColorAlphaSlider
105
- color={state.colorState.color.hex}
106
- modelValue={state.colorState.color.a * 100}
107
- onChange={handler.alphaChange}
108
- disabled={!props.enableAlpha}
109
- />
110
- </div>
111
- <div className="color-panel-slider-color" style={{ backgroundColor: state.colorState.color.hex }}/>
112
- </div>
113
- {editor.renderContent.value()}
114
- </div>
115
- {history.renderContent.value()}
116
- </div>
117
- )
118
- };
119
- },
120
- });
121
-
122
- interface iColorState {
123
- color: PlainColor,
124
- value: string | null | undefined
125
- }
1
+ import './color-panel.scss';
2
+ import {designComponent, getComponentCls, iMouseEvent, reactive, useModel} from "@peryl/react-compose";
3
+ import {ColorSvPanel} from "./sub/ColorSvPanel";
4
+ import {ColorHueSlider} from "./sub/ColorHueSlider";
5
+ import {ColorAlphaSlider} from "./sub/ColorAlphaSlider";
6
+ import {PlainColor} from "./utils/PlainColor";
7
+ import {useColorPanelEditor} from "./useColorPanelEditor";
8
+ import {useColorPanelHistory} from "./useColorPanelHistory";
9
+ import {ColorPanelPublicPropOptions} from "./utils/color-picker.utils";
10
+ import {Icon} from "../Icon";
11
+ import {$message} from "../$message";
12
+ import {i18n} from "../i18n";
13
+
14
+
15
+ export const ColorPanel = designComponent({
16
+ name: 'color-panel',
17
+ props: {
18
+ ...ColorPanelPublicPropOptions
19
+ },
20
+ emits: {
21
+ onUpdateModelValue: (val: any) => true,
22
+ onDblclickSvPanel: (e: iMouseEvent) => true,
23
+ },
24
+ inheritPropsType: HTMLDivElement,
25
+ setup({ props, event: { emit } }) {
26
+
27
+ const model = useModel(() => props.modelValue, emit.onUpdateModelValue, {
28
+ onChange: (value) => {
29
+ const prev = state.colorState;
30
+ const colorState = utils.getState(value, prev);
31
+ if (colorState !== prev) {
32
+ state.colorState = colorState;
33
+ }
34
+ },
35
+ });
36
+
37
+ const utils = {
38
+ getState: (value: string | null | undefined, prev?: iColorState): iColorState => {
39
+ if (!prev) {
40
+ return { color: new PlainColor(value || '#FFFFFF'), value };
41
+ } else {
42
+ if (prev.value == value) {
43
+ return prev;
44
+ } else {
45
+ return { color: new PlainColor(value || '#FFFFFF'), value };
46
+ }
47
+ }
48
+ },
49
+ };
50
+
51
+ const state = reactive({
52
+ colorState: utils.getState(model.value)
53
+ });
54
+
55
+ const handler = {
56
+ svChange: ({ value, saturation }: { value: number, saturation: number }) => {
57
+ const color = state.colorState.color.useHsva({ v: value, s: saturation });
58
+ state.colorState = { color, value: color.value };
59
+ model.value = state.colorState.value!;
60
+ },
61
+ hueChange: (hue: number) => {
62
+ const color = state.colorState.color.useHsva({ h: hue });
63
+ state.colorState = { color, value: color.value };
64
+ model.value = state.colorState.value!;
65
+ },
66
+ alphaChange: (alpha: number) => {
67
+ const color = state.colorState.color.useHsva({ a: alpha / 100 });
68
+ state.colorState = { color, value: color.value };
69
+ model.value = state.colorState.value!;
70
+ },
71
+ dropColor: () => {
72
+ if (!('EyeDropper' in window)) {
73
+ $message.error(i18n.$it('colorPicker.notSupportDropper').d('您的浏览器不支持颜色拾取器,推荐使用谷歌浏览器'));
74
+ return;
75
+ }
76
+ const close = $message(i18n.$it('colorPicker.exitDropperMode').d('按 ESC 键关闭取色吸管'), { time: null });
77
+ const eyeDropper = new (window as any).EyeDropper();
78
+ eyeDropper.open().then((result: { sRGBHex: string }) => {
79
+ state.colorState = utils.getState(result.sRGBHex);
80
+ model.value = state.colorState.value!;
81
+ close();
82
+ }).catch(() => {
83
+ close();
84
+ });
85
+ },
86
+ };
87
+
88
+ const editor = useColorPanelEditor({
89
+ props,
90
+ getColor: () => state.colorState.color,
91
+ onChange: color => {
92
+ state.colorState = { color, value: color.value };
93
+ model.value = color.value;
94
+ }
95
+ });
96
+
97
+ const history = useColorPanelHistory({
98
+ onChange: color => {
99
+ state.colorState = { color, value: color.value };
100
+ model.value = color.value;
101
+ }
102
+ });
103
+
104
+ return {
105
+ render: () => (
106
+ <div className={getComponentCls('color-panel')}>
107
+ <div className="color-panel-card">
108
+ <ColorSvPanel
109
+ hue={state.colorState.color.h}
110
+ modelValue={state.colorState.color.v}
111
+ saturation={state.colorState.color.s}
112
+ onChange={handler.svChange}
113
+ onDblclick={emit.onDblclickSvPanel}
114
+ disable={props.disableSvPanel}
115
+ />
116
+ <div className="color-panel-slider-bar">
117
+ <div className="color-panel-dropper" onClick={handler.dropColor}>
118
+ <Icon icon="ie-dropper"/>
119
+ </div>
120
+ <div className="color-panel-slider-container">
121
+ <ColorHueSlider
122
+ modelValue={state.colorState.color.h}
123
+ onChange={handler.hueChange}
124
+ />
125
+ <ColorAlphaSlider
126
+ color={state.colorState.color.hex}
127
+ modelValue={state.colorState.color.a * 100}
128
+ onChange={handler.alphaChange}
129
+ disabled={!props.enableAlpha}
130
+ />
131
+ </div>
132
+ <div className="color-panel-slider-color" style={{ backgroundColor: state.colorState.color.hex }}/>
133
+ </div>
134
+ {editor.renderContent.value()}
135
+ </div>
136
+ {history.renderContent.value()}
137
+ </div>
138
+ )
139
+ };
140
+ },
141
+ });
142
+
143
+ interface iColorState {
144
+ color: PlainColor,
145
+ value: string | null | undefined
146
+ }
@@ -1,97 +1,117 @@
1
- @include prefix(color-panel) {
2
- display: inline-flex;
3
- flex-direction: column;
4
- align-items: stretch;
5
- justify-content: flex-start;
6
- border: solid 1px plv(border-color);
7
- background-color: plv(background-light);
8
-
9
- .color-panel-card {
10
- padding: 10px 10px 0;
11
- }
12
-
13
- .color-panel-slider-bar {
14
- display: flex;
15
-
16
- .color-panel-slider-container {
17
- flex: 1;
18
- overflow: hidden;
19
-
20
- @include comp(color-slider) {
21
- margin-top: 4px;
22
- }
23
- }
24
-
25
- .color-panel-slider-color {
26
- margin-top: 4px;
27
- height: 24px;
28
- width: 24px;
29
- margin-left: 4px;
30
- border-radius: plv(box-size-small-border-radius);
31
- box-shadow: rgb(0 0 0 / 15%) 0 0 0 1px inset, rgb(0 0 0 / 25%) 0 0 4px inset;
32
- }
33
- }
34
-
35
- .color-panel-editor {
36
- margin-top: 4px;
37
- font-size: 12px;
38
- width: 200px;
39
-
40
- $hexWidth: 60px;
41
-
42
- & > div {
43
- display: inline-flex;
44
- flex-direction: column;
45
- align-items: center;
46
- justify-content: center;
47
- width: calc((200px - #{$hexWidth}) / 4);
48
- box-sizing: border-box;
49
-
50
- &:first-child {
51
- width: $hexWidth;
52
- }
53
-
54
- &:not(:first-child) {
55
- padding-left: 6px;
56
- }
57
-
58
- input {
59
- margin-bottom: 4px;
60
- width: 100%;
61
- font-size: 12px;
62
- height: 20px;
63
- padding: 0;
64
- border-radius: 0;
65
- box-shadow: #{plv(secondary-4)} 0 0 0 1px inset;
66
- border: none;
67
- outline: none;
68
- text-align: center;
69
- background-color: plv(background-light);
70
- color: plv(text-2);
71
- border-radius: plv(box-size-small-border-radius);
72
- }
73
- }
74
- }
75
-
76
- .color-panel-history {
77
- display: flex;
78
- flex-wrap: wrap;
79
- width: 200px;
80
- margin-top: 5px;
81
- border-top: solid 1px plv(border-color);
82
- padding: 10px 10px 0;
83
-
84
- .color-panel-history-item {
85
- height: 16px;
86
- width: 16px;
87
- margin-bottom: 10px;
88
- box-shadow: rgba(0, 0, 0, 0.15) 0 0 0 1px inset, rgba(0, 0, 0, 0.25) 0 0 4px inset;
89
- cursor: pointer;
90
- border-radius: plv(box-size-small-border-radius);
91
-
92
- &:not(:nth-child(8n)) {
93
- margin-right: 10px;
94
- }
95
- }
96
- }
97
- }
1
+ @include prefix(color-panel) {
2
+ display: inline-flex;
3
+ flex-direction: column;
4
+ align-items: stretch;
5
+ justify-content: flex-start;
6
+ border: solid 1px plv(border-color);
7
+ background-color: plv(background-light);
8
+
9
+ .color-panel-card {
10
+ padding: 10px 10px 0;
11
+ }
12
+
13
+ .color-panel-slider-bar {
14
+ display: flex;
15
+
16
+ .color-panel-slider-container {
17
+ flex: 1;
18
+ overflow: hidden;
19
+
20
+ @include comp(color-slider) {
21
+ margin-top: 4px;
22
+ }
23
+ }
24
+
25
+ .color-panel-slider-color {
26
+ margin-top: 4px;
27
+ height: 24px;
28
+ width: 24px;
29
+ margin-left: 4px;
30
+ border-radius: plv(box-size-small-border-radius);
31
+ box-shadow: rgb(0 0 0 / 15%) 0 0 0 1px inset, rgb(0 0 0 / 25%) 0 0 4px inset;
32
+ }
33
+
34
+ .color-panel-dropper {
35
+ margin-top: 4px;
36
+ height: 24px;
37
+ width: 24px;
38
+ margin-right: 4px;
39
+ border-radius: plv(box-size-small-border-radius);
40
+ //box-shadow: rgb(0 0 0 / 15%) 0 0 0 1px inset, rgb(0 0 0 / 25%) 0 0 4px inset;
41
+ display: flex;
42
+ align-items: center;
43
+ justify-content: center;
44
+ background-color: plv(secondary-light-2);
45
+ transition: all ease 300ms;
46
+ cursor: pointer;
47
+
48
+ &:hover {
49
+ background-color: plv(primary-6);
50
+ color: plv(pbfc);
51
+ }
52
+ }
53
+ }
54
+
55
+ .color-panel-editor {
56
+ margin-top: 4px;
57
+ font-size: 12px;
58
+ width: 200px;
59
+
60
+ $hexWidth: 60px;
61
+
62
+ & > div {
63
+ display: inline-flex;
64
+ flex-direction: column;
65
+ align-items: center;
66
+ justify-content: center;
67
+ width: calc((200px - #{$hexWidth}) / 4);
68
+ box-sizing: border-box;
69
+
70
+ &:first-child {
71
+ width: $hexWidth;
72
+ }
73
+
74
+ &:not(:first-child) {
75
+ padding-left: 6px;
76
+ }
77
+
78
+ input {
79
+ margin-bottom: 4px;
80
+ width: 100%;
81
+ font-size: 12px;
82
+ height: 20px;
83
+ padding: 0;
84
+ border-radius: 0;
85
+ box-shadow: #{plv(secondary-4)} 0 0 0 1px inset;
86
+ border: none;
87
+ outline: none;
88
+ text-align: center;
89
+ background-color: plv(background-light);
90
+ color: plv(text-2);
91
+ border-radius: plv(box-size-small-border-radius);
92
+ }
93
+ }
94
+ }
95
+
96
+ .color-panel-history {
97
+ display: flex;
98
+ flex-wrap: wrap;
99
+ width: 200px;
100
+ margin-top: 5px;
101
+ border-top: solid 1px plv(border-color);
102
+ padding: 10px 10px 0;
103
+
104
+ .color-panel-history-item {
105
+ height: 16px;
106
+ width: 16px;
107
+ margin-bottom: 10px;
108
+ box-shadow: rgba(0, 0, 0, 0.15) 0 0 0 1px inset, rgba(0, 0, 0, 0.25) 0 0 4px inset;
109
+ cursor: pointer;
110
+ border-radius: plv(box-size-small-border-radius);
111
+
112
+ &:not(:nth-child(8n)) {
113
+ margin-right: 10px;
114
+ }
115
+ }
116
+ }
117
+ }