@fluentui/web-components 2.4.0 → 2.5.2
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.json +61 -1
- package/CHANGELOG.md +29 -2
- package/dist/dts/_docs/design-system/color-explorer/app.d.ts +25 -0
- package/dist/dts/_docs/design-system/color-explorer/colors.d.ts +13 -0
- package/dist/dts/_docs/design-system/color-explorer/component-types.d.ts +6 -0
- package/dist/dts/_docs/design-system/color-explorer/components/color-block.d.ts +10 -0
- package/dist/dts/_docs/design-system/color-explorer/components/color-picker/color-picker.d.ts +190 -0
- package/dist/dts/_docs/design-system/color-explorer/components/color-picker/color-picker.form-associated.d.ts +15 -0
- package/dist/dts/_docs/design-system/color-explorer/components/color-picker/color-picker.styles.d.ts +3 -0
- package/dist/dts/_docs/design-system/color-explorer/components/color-picker/color-picker.template.d.ts +8 -0
- package/dist/dts/_docs/design-system/color-explorer/components/color-picker/index.d.ts +9 -0
- package/dist/dts/_docs/design-system/color-explorer/components/control-pane/control-pane.d.ts +8 -0
- package/dist/dts/_docs/design-system/color-explorer/components/control-pane/control-pane.styles.d.ts +1 -0
- package/dist/dts/_docs/design-system/color-explorer/components/control-pane/control-pane.template.d.ts +2 -0
- package/dist/dts/_docs/design-system/color-explorer/components/control-pane/index.d.ts +6 -0
- package/dist/dts/_docs/design-system/color-explorer/components/gradient/gradient.d.ts +5 -0
- package/dist/dts/_docs/design-system/color-explorer/components/gradient/gradient.styles.d.ts +1 -0
- package/dist/dts/_docs/design-system/color-explorer/components/gradient/gradient.template.d.ts +2 -0
- package/dist/dts/_docs/design-system/color-explorer/components/gradient/index.d.ts +6 -0
- package/dist/dts/_docs/design-system/color-explorer/components/layer-background/index.d.ts +21 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-app/index.d.ts +6 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-app/sample-app.d.ts +3 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-app/sample-app.styles.d.ts +1 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-app/sample-app.template.d.ts +1 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-page/index.d.ts +6 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-page/sample-page.d.ts +3 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-page/sample-page.styles.d.ts +1 -0
- package/dist/dts/_docs/design-system/color-explorer/components/sample-page/sample-page.template.d.ts +1 -0
- package/dist/dts/_docs/design-system/color-explorer/components/swatch.d.ts +30 -0
- package/dist/dts/_docs/design-system/color-explorer/custom-elements.d.ts +7 -0
- package/dist/dts/_docs/design-system/color-explorer/index.d.ts +2 -0
- package/dist/dts/design-tokens.d.ts +20 -0
- package/dist/dts/styles/patterns/index.d.ts +1 -0
- package/dist/dts/styles/patterns/type-ramp.d.ts +18 -0
- package/dist/dts/utilities/type-ramp.d.ts +12 -0
- package/dist/esm/_docs/design-system/color-explorer/app.js +247 -0
- package/dist/esm/_docs/design-system/color-explorer/colors.js +24 -0
- package/dist/esm/_docs/design-system/color-explorer/component-types.js +7 -0
- package/dist/esm/_docs/design-system/color-explorer/components/color-block.js +408 -0
- package/dist/esm/_docs/design-system/color-explorer/components/color-picker/color-picker.form-associated.js +16 -0
- package/dist/esm/_docs/design-system/color-explorer/components/color-picker/color-picker.js +297 -0
- package/dist/esm/_docs/design-system/color-explorer/components/color-picker/color-picker.styles.js +124 -0
- package/dist/esm/_docs/design-system/color-explorer/components/color-picker/color-picker.template.js +130 -0
- package/dist/esm/_docs/design-system/color-explorer/components/color-picker/index.js +15 -0
- package/dist/esm/_docs/design-system/color-explorer/components/control-pane/control-pane.js +24 -0
- package/dist/esm/_docs/design-system/color-explorer/components/control-pane/control-pane.styles.js +19 -0
- package/dist/esm/_docs/design-system/color-explorer/components/control-pane/control-pane.template.js +52 -0
- package/dist/esm/_docs/design-system/color-explorer/components/control-pane/index.js +18 -0
- package/dist/esm/_docs/design-system/color-explorer/components/gradient/gradient.js +11 -0
- package/dist/esm/_docs/design-system/color-explorer/components/gradient/gradient.styles.js +31 -0
- package/dist/esm/_docs/design-system/color-explorer/components/gradient/gradient.template.js +21 -0
- package/dist/esm/_docs/design-system/color-explorer/components/gradient/index.js +18 -0
- package/dist/esm/_docs/design-system/color-explorer/components/layer-background/index.js +70 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-app/index.js +18 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-app/sample-app.js +3 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-app/sample-app.styles.js +166 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-app/sample-app.template.js +97 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-page/index.js +18 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-page/sample-page.js +3 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-page/sample-page.styles.js +130 -0
- package/dist/esm/_docs/design-system/color-explorer/components/sample-page/sample-page.template.js +82 -0
- package/dist/esm/_docs/design-system/color-explorer/components/swatch.js +163 -0
- package/dist/esm/_docs/design-system/color-explorer/custom-elements.js +3 -0
- package/dist/esm/_docs/design-system/color-explorer/index.js +14 -0
- package/dist/esm/accordion/accordion-item/accordion-item.styles.js +4 -5
- package/dist/esm/accordion/accordion.styles.js +3 -4
- package/dist/esm/badge/badge.styles.js +3 -4
- package/dist/esm/breadcrumb/breadcrumb.styles.js +2 -4
- package/dist/esm/breadcrumb-item/breadcrumb-item.styles.js +3 -4
- package/dist/esm/calendar/calendar.styles.js +3 -4
- package/dist/esm/checkbox/checkbox.styles.js +3 -4
- package/dist/esm/combobox/combobox.styles.js +3 -3
- package/dist/esm/data-grid/data-grid-cell.styles.js +3 -5
- package/dist/esm/design-tokens.js +38 -1
- package/dist/esm/listbox-option/listbox-option.styles.js +3 -4
- package/dist/esm/menu-item/menu-item.styles.js +3 -4
- package/dist/esm/radio/radio.styles.js +3 -4
- package/dist/esm/search/search.styles.js +3 -4
- package/dist/esm/select/select.styles.js +3 -4
- package/dist/esm/slider-label/slider-label.styles.js +3 -2
- package/dist/esm/styles/patterns/button.styles.js +3 -4
- package/dist/esm/styles/patterns/index.js +1 -0
- package/dist/esm/styles/patterns/input.styles.js +4 -6
- package/dist/esm/styles/patterns/type-ramp.js +74 -0
- package/dist/esm/switch/switch.styles.js +4 -5
- package/dist/esm/tabs/tab/tab.styles.js +3 -5
- package/dist/esm/tabs/tab-panel/tab-panel.styles.js +3 -5
- package/dist/esm/tabs/tabs.styles.js +3 -4
- package/dist/esm/tooltip/tooltip.styles.js +3 -4
- package/dist/esm/tree-item/tree-item.styles.js +3 -4
- package/dist/esm/utilities/type-ramp.js +12 -0
- package/dist/fluent-web-components.api.json +534 -0
- package/dist/web-components.d.ts +57 -0
- package/dist/web-components.js +191 -28
- package/dist/web-components.min.js +211 -139
- package/docs/api-report.md +57 -0
- package/package.json +2 -2
- package/public/SegoeUI-VF.ttf +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FormAssociated, FoundationElement } from '@microsoft/fast-foundation';
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
class _ColorPicker extends FoundationElement {
|
|
4
|
+
}
|
|
5
|
+
/* eslint-enable */
|
|
6
|
+
/**
|
|
7
|
+
* A form-associated base class for the component.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export class FormAssociatedColorPicker extends FormAssociated(_ColorPicker) {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.proxy = document.createElement('input');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { ColorHSV, ColorRGBA64, hsvToRGB, parseColor, rgbToHSV } from '@microsoft/fast-colors';
|
|
3
|
+
import { attr, DOM, observable } from '@microsoft/fast-element';
|
|
4
|
+
import { isNullOrWhiteSpace } from '@microsoft/fast-web-utilities';
|
|
5
|
+
import { FormAssociatedColorPicker } from './color-picker.form-associated';
|
|
6
|
+
/**
|
|
7
|
+
* This is currently experimental, any use of the color picker must include the following
|
|
8
|
+
* imports and register with the DesignSystem
|
|
9
|
+
*
|
|
10
|
+
* import { fastTextField } from "@microsoft/fast-components";
|
|
11
|
+
* import { DesignSystem } from "@microsoft/fast-foundation";
|
|
12
|
+
* DesignSystem.getOrCreate().register(fastTextField());
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Simple class for storing all of the color picker UI observable values.
|
|
16
|
+
*/
|
|
17
|
+
class ColorPickerUI {
|
|
18
|
+
constructor(rgbColor, hsvColor) {
|
|
19
|
+
this.RGBColor = rgbColor;
|
|
20
|
+
this.HSVColor = hsvColor;
|
|
21
|
+
this.HueCSSColor = hsvToRGB(new ColorHSV(this.HSVColor.h, 1, 1)).toStringHexRGB();
|
|
22
|
+
this.HuePosition = (this.HSVColor.h / 360) * 100;
|
|
23
|
+
this.SatValLeftPos = this.HSVColor.s * 100;
|
|
24
|
+
this.SatValTopPos = 100 - this.HSVColor.v * 100;
|
|
25
|
+
this.AlphaPos = this.RGBColor.a * 100;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A Color Picker Custom HTML Element.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export class ColorPicker extends FormAssociatedColorPicker {
|
|
34
|
+
constructor() {
|
|
35
|
+
super(...arguments);
|
|
36
|
+
/**
|
|
37
|
+
* Flag indicating that the color UI is activily listening for mouse move and up events.
|
|
38
|
+
*/
|
|
39
|
+
this.mouseActive = false;
|
|
40
|
+
/**
|
|
41
|
+
* Object containing all of the properties displayed in the color picker UI.
|
|
42
|
+
*/
|
|
43
|
+
this.uiValues = new ColorPickerUI(new ColorRGBA64(1, 0, 0), new ColorHSV(0, 1, 1));
|
|
44
|
+
/**
|
|
45
|
+
* A reference to the HTMLElement that is the current target of mouse move events.
|
|
46
|
+
*/
|
|
47
|
+
this.currentMouseTarget = null;
|
|
48
|
+
}
|
|
49
|
+
readOnlyChanged() {
|
|
50
|
+
if (this.proxy instanceof HTMLElement) {
|
|
51
|
+
this.proxy.readOnly = this.readOnly;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
autofocusChanged() {
|
|
55
|
+
if (this.proxy instanceof HTMLElement) {
|
|
56
|
+
this.proxy.autofocus = this.autofocus;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
placeholderChanged() {
|
|
60
|
+
if (this.proxy instanceof HTMLElement) {
|
|
61
|
+
this.proxy.placeholder = this.placeholder;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
connectedCallback() {
|
|
68
|
+
super.connectedCallback();
|
|
69
|
+
this.open = false;
|
|
70
|
+
this.initColorValues();
|
|
71
|
+
this.proxy.setAttribute('type', 'color');
|
|
72
|
+
if (this.autofocus) {
|
|
73
|
+
DOM.queueUpdate(() => {
|
|
74
|
+
this.focus();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Handles the focus event. When the template has focus the color UI will be visable.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
handleFocus() {
|
|
83
|
+
// Re-init colors in case the value changed externally since the UI was last visible.
|
|
84
|
+
this.initColorValues();
|
|
85
|
+
this.open = true;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Handles the blur event. Hides the color UI when the template loses focus.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
handleBlur() {
|
|
92
|
+
this.open = false;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Handles the internal control's `input` event. This event is fired whenever a user types directly into the primary text field.
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
handleTextInput() {
|
|
99
|
+
this.initialValue = this.control.value;
|
|
100
|
+
if (this.isValideCSSColor(this.value)) {
|
|
101
|
+
this.currentRGBColor = parseColor(this.value);
|
|
102
|
+
this.currentHSVColor = rgbToHSV(this.currentRGBColor);
|
|
103
|
+
this.updateUIValues(false);
|
|
104
|
+
this.$emit('change');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Handles the mouse down event on the Sat/Val square and Hue and Alpha sliders. Sets the current targeted element and begins listening for mouse move events.
|
|
109
|
+
* @param param ['sv','h','a'] - string specifying which color property is being modified with the mouse.
|
|
110
|
+
* @param e - A reference to the mouse event.
|
|
111
|
+
*/
|
|
112
|
+
handleMouseDown(param, e) {
|
|
113
|
+
this.currentMouseTarget = e.composedPath()[0];
|
|
114
|
+
this.currentMouseParam = param;
|
|
115
|
+
this.updateFromMouseEvent(e.pageX, e.pageY);
|
|
116
|
+
this.mouseActive = true;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Handles the mouse move event within the color UI. Is only called once the mouseActive is set to true.
|
|
120
|
+
* @param e - Reference to the Mouse Event
|
|
121
|
+
*/
|
|
122
|
+
handleMouseMove(e) {
|
|
123
|
+
this.updateFromMouseEvent(e.pageX, e.pageY);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Handles the mouse up event within the color UI. Disables listening for mouse move events.
|
|
127
|
+
* @param e - Reference to the Mouse Event
|
|
128
|
+
*/
|
|
129
|
+
handleMouseUp(e) {
|
|
130
|
+
this.updateFromMouseEvent(e.pageX, e.pageY);
|
|
131
|
+
this.currentMouseTarget = null;
|
|
132
|
+
this.currentMouseParam = null;
|
|
133
|
+
this.mouseActive = false;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Handles changes to any of the color property text inputs typed by the user.
|
|
137
|
+
* @param param ['r','g','b','a','h','s','v'] - String specifying which color value is being modified.
|
|
138
|
+
* @param e - Reference to the event.
|
|
139
|
+
*/
|
|
140
|
+
handleTextValueInput(param, e) {
|
|
141
|
+
const inputVal = e.composedPath()[0].value;
|
|
142
|
+
if (isNullOrWhiteSpace(inputVal) || Number.isNaN(inputVal)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const newVal = parseInt(inputVal, 10);
|
|
146
|
+
if (['r', 'g', 'b', 'a'].includes(param)) {
|
|
147
|
+
if ((param !== 'a' && this.isValidRGB(newVal)) || (param === 'a' && this.isValidAlpha(newVal))) {
|
|
148
|
+
this.currentRGBColor = new ColorRGBA64(param === 'r' ? newVal / 255 : this.currentRGBColor.r, param === 'g' ? newVal / 255 : this.currentRGBColor.g, param === 'b' ? newVal / 255 : this.currentRGBColor.b, param === 'a' ? newVal / 100 : this.currentRGBColor.a);
|
|
149
|
+
this.currentHSVColor = rgbToHSV(this.currentRGBColor);
|
|
150
|
+
this.updateUIValues(true);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (['h', 's', 'v'].includes(param)) {
|
|
154
|
+
if ((param !== 'h' && this.isValidSaturationValue(newVal)) || (param === 'h' && this.isValidHue(newVal))) {
|
|
155
|
+
this.updateHSV(param === 'h' ? newVal : this.currentHSVColor.h, param === 's' ? newVal / 100 : this.currentHSVColor.s, param === 'v' ? newVal / 100 : this.currentHSVColor.v);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Change event handler for inner control.
|
|
161
|
+
* @remarks
|
|
162
|
+
* "Change" events are not `composable` so they will not
|
|
163
|
+
* permeate the shadow DOM boundary. This fn effectively proxies
|
|
164
|
+
* the change event, emitting a `change` event whenever the internal
|
|
165
|
+
* control emits a `change` event
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
handleChange() {
|
|
169
|
+
this.$emit('change');
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Initialize internal color values based on input value and set the UI elements
|
|
173
|
+
* to the correct positions / values.
|
|
174
|
+
*/
|
|
175
|
+
initColorValues() {
|
|
176
|
+
if (!isNullOrWhiteSpace(this.value)) {
|
|
177
|
+
this.currentRGBColor = parseColor(this.value);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this.currentRGBColor = new ColorRGBA64(1, 0, 0, 1);
|
|
181
|
+
}
|
|
182
|
+
this.currentHSVColor = rgbToHSV(this.currentRGBColor);
|
|
183
|
+
this.updateUIValues(false);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Determines if a number value is within the valid range for an R, G, or B color channel.
|
|
187
|
+
* @param val - Number to be evaluated.
|
|
188
|
+
*/
|
|
189
|
+
isValidRGB(val) {
|
|
190
|
+
return val >= 0 && val <= 255;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Determines if a number value is within the valid range for the alpha channel.
|
|
194
|
+
* @param val - Number to be evaluated.
|
|
195
|
+
*/
|
|
196
|
+
isValidAlpha(val) {
|
|
197
|
+
return val >= 0 && val <= 100;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Determines if a number value is within the valid range for the saturation or value color channels.
|
|
201
|
+
* @param val - Number to be evaluated.
|
|
202
|
+
*/
|
|
203
|
+
isValidSaturationValue(val) {
|
|
204
|
+
return val >= 0 && val <= 100;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Determines if a number value is within the valid range for the hue color channel.
|
|
208
|
+
* @param val - Number to be evaluated.
|
|
209
|
+
*/
|
|
210
|
+
isValidHue(val) {
|
|
211
|
+
return val >= 0 && val <= 359;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Checks if input is a valid CSS color.
|
|
215
|
+
* After placing an invalid css color value into a color style property the value will be an empty string when read back.
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
isValideCSSColor(testValue) {
|
|
219
|
+
/* Set the background color of the proxy element since it is not visible in the UI. */
|
|
220
|
+
this.proxy.style.backgroundColor = '';
|
|
221
|
+
this.proxy.style.backgroundColor = testValue;
|
|
222
|
+
/* Read the value back out. If it was not a valid color value then it will be an empty string when read back out. */
|
|
223
|
+
return this.proxy.style.backgroundColor !== '';
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Update the current color values to a new HSV color.
|
|
227
|
+
* @param hue The new Hue value.
|
|
228
|
+
* @param sat The new saturation value.
|
|
229
|
+
* @param val The new Value value.
|
|
230
|
+
*/
|
|
231
|
+
updateHSV(hue, sat, val) {
|
|
232
|
+
this.currentHSVColor = new ColorHSV(hue, sat, val);
|
|
233
|
+
this.currentRGBColor = hsvToRGB(this.currentHSVColor, this.currentRGBColor.a);
|
|
234
|
+
this.updateUIValues(true);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Update the current color values based on the mouse position over one of the three UI elements (hue, saturation/value, or alpha).
|
|
238
|
+
* @param pageX The pageX position of the mouse.
|
|
239
|
+
* @param pageY The pageY position of the mouse.
|
|
240
|
+
*/
|
|
241
|
+
updateFromMouseEvent(pageX, pageY) {
|
|
242
|
+
const pos = this.currentMouseTarget.getBoundingClientRect();
|
|
243
|
+
let x = pageX - pos.left;
|
|
244
|
+
let y = pageY - pos.top;
|
|
245
|
+
const width = pos.width;
|
|
246
|
+
const height = pos.height;
|
|
247
|
+
if (x > width)
|
|
248
|
+
x = width;
|
|
249
|
+
if (y > height)
|
|
250
|
+
y = height;
|
|
251
|
+
if (x < 0)
|
|
252
|
+
x = 0;
|
|
253
|
+
if (y < 0)
|
|
254
|
+
y = 0;
|
|
255
|
+
if (this.currentMouseParam === 'h') {
|
|
256
|
+
this.updateHSV((359 * x) / width, this.currentHSVColor.s, this.currentHSVColor.v);
|
|
257
|
+
}
|
|
258
|
+
else if (this.currentMouseParam === 'sv') {
|
|
259
|
+
this.updateHSV(this.currentHSVColor.h, Math.round((x * 100) / width) / 100, Math.round(100 - (y * 100) / height) / 100);
|
|
260
|
+
}
|
|
261
|
+
else if (this.currentMouseParam === 'a') {
|
|
262
|
+
this.currentRGBColor = new ColorRGBA64(this.currentRGBColor.r, this.currentRGBColor.g, this.currentRGBColor.b, Math.round((x * 100) / width) / 100);
|
|
263
|
+
this.updateUIValues(true);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Update the UI values with the current color. This updates the position of the indicators over the Sat/Val, Hue and Alpha elements
|
|
268
|
+
* and the values in all of the text fields at once.
|
|
269
|
+
* @param updateValue - Flag to trigger updating of the main text field value and emitting the change event.
|
|
270
|
+
*/
|
|
271
|
+
updateUIValues(updateValue) {
|
|
272
|
+
this.uiValues = new ColorPickerUI(this.currentRGBColor, this.currentHSVColor);
|
|
273
|
+
if (updateValue) {
|
|
274
|
+
this.initialValue =
|
|
275
|
+
this.currentRGBColor.a !== 1 ? this.currentRGBColor.toStringWebRGBA() : this.currentRGBColor.toStringHexRGB();
|
|
276
|
+
this.$emit('change');
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
__decorate([
|
|
281
|
+
attr({ attribute: 'readonly', mode: 'boolean' })
|
|
282
|
+
], ColorPicker.prototype, "readOnly", void 0);
|
|
283
|
+
__decorate([
|
|
284
|
+
attr({ mode: 'boolean' })
|
|
285
|
+
], ColorPicker.prototype, "autofocus", void 0);
|
|
286
|
+
__decorate([
|
|
287
|
+
attr
|
|
288
|
+
], ColorPicker.prototype, "placeholder", void 0);
|
|
289
|
+
__decorate([
|
|
290
|
+
observable
|
|
291
|
+
], ColorPicker.prototype, "open", void 0);
|
|
292
|
+
__decorate([
|
|
293
|
+
observable
|
|
294
|
+
], ColorPicker.prototype, "mouseActive", void 0);
|
|
295
|
+
__decorate([
|
|
296
|
+
observable
|
|
297
|
+
], ColorPicker.prototype, "uiValues", void 0);
|
package/dist/esm/_docs/design-system/color-explorer/components/color-picker/color-picker.styles.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { css } from "@microsoft/fast-element";
|
|
2
|
+
export const colorPickerStyles = () => css `
|
|
3
|
+
.popup,
|
|
4
|
+
.popup__open {
|
|
5
|
+
display: none;
|
|
6
|
+
padding: 2px;
|
|
7
|
+
flex-direction: row;
|
|
8
|
+
background-color: var(--neutral-layer-floating);
|
|
9
|
+
border: calc(var(--outline-width) * 1px) solid var(--neutral-outline-rest);
|
|
10
|
+
border-radius: calc(var(--corner-radius) * 1px);
|
|
11
|
+
}
|
|
12
|
+
.popup__open {
|
|
13
|
+
display: flex;
|
|
14
|
+
position: absolute;
|
|
15
|
+
z-index: 1;
|
|
16
|
+
margin-left: -32px;
|
|
17
|
+
}
|
|
18
|
+
.pickers {
|
|
19
|
+
margin: 4px 6px 4px 4px;
|
|
20
|
+
}
|
|
21
|
+
.inputs {
|
|
22
|
+
width: 65px;
|
|
23
|
+
margin: 0 4px 4px 0;
|
|
24
|
+
}
|
|
25
|
+
.pickers-saturation {
|
|
26
|
+
position: relative;
|
|
27
|
+
width: 200px;
|
|
28
|
+
height: 200px;
|
|
29
|
+
margin-bottom: 17px;
|
|
30
|
+
background: linear-gradient(to top, #000 0%, rgba(0, 0, 0, 0) 100%),
|
|
31
|
+
linear-gradient(to right, #fff 0%, rgba(255, 255, 255, 0) 100%);
|
|
32
|
+
background-color: #f00;
|
|
33
|
+
border: 1px solid #fff;
|
|
34
|
+
}
|
|
35
|
+
.saturation-indicator {
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
left: 0;
|
|
39
|
+
border: 1px solid #fff;
|
|
40
|
+
border-radius: 3px;
|
|
41
|
+
width: 4px;
|
|
42
|
+
height: 4px;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
}
|
|
45
|
+
.pickers-hue {
|
|
46
|
+
position: relative;
|
|
47
|
+
width: 200px;
|
|
48
|
+
height: 30px;
|
|
49
|
+
margin-bottom: 17px;
|
|
50
|
+
border: 1px solid #fff;
|
|
51
|
+
background: linear-gradient(
|
|
52
|
+
to right,
|
|
53
|
+
#f00 0%,
|
|
54
|
+
#ff0 16.66%,
|
|
55
|
+
#0f0 33.33%,
|
|
56
|
+
#0ff 50%,
|
|
57
|
+
#00f 66.66%,
|
|
58
|
+
#f0f 83.33%,
|
|
59
|
+
#f00 100%
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
.hue-indicator,
|
|
63
|
+
.alpha-indicator {
|
|
64
|
+
position: absolute;
|
|
65
|
+
left: 0;
|
|
66
|
+
top: -2px;
|
|
67
|
+
border: 1px solid #fff;
|
|
68
|
+
width: 1px;
|
|
69
|
+
height: 32px;
|
|
70
|
+
pointer-events: none;
|
|
71
|
+
margin-left: 1px;
|
|
72
|
+
}
|
|
73
|
+
.pickers-alpha {
|
|
74
|
+
position: relative;
|
|
75
|
+
width: 200px;
|
|
76
|
+
height: 30px;
|
|
77
|
+
border: 1px solid #fff;
|
|
78
|
+
background-image: linear-gradient(45deg, #999 25%, transparent 25%),
|
|
79
|
+
linear-gradient(-45deg, #999 25%, transparent 25%),
|
|
80
|
+
linear-gradient(45deg, transparent 75%, #999 75%),
|
|
81
|
+
linear-gradient(-45deg, transparent 75%, #999 75%);
|
|
82
|
+
background-size: 20px 20px;
|
|
83
|
+
background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
|
|
84
|
+
background-color: #fff;
|
|
85
|
+
}
|
|
86
|
+
.alpha-mask {
|
|
87
|
+
width: 100%;
|
|
88
|
+
height: 100%;
|
|
89
|
+
background-image: linear-gradient(to right, transparent, #f00);
|
|
90
|
+
margin-bottom: 5px;
|
|
91
|
+
}
|
|
92
|
+
.control-color {
|
|
93
|
+
position: relative;
|
|
94
|
+
display: inline-block;
|
|
95
|
+
width: 25px;
|
|
96
|
+
height: 25px;
|
|
97
|
+
margin-top: auto;
|
|
98
|
+
margin-bottom: auto;
|
|
99
|
+
border: 1px solid var(--fast-tooling-l1-color, #333333);
|
|
100
|
+
}
|
|
101
|
+
.control-color::before {
|
|
102
|
+
position: absolute;
|
|
103
|
+
content: "";
|
|
104
|
+
left: 0;
|
|
105
|
+
right: 0;
|
|
106
|
+
top: 0;
|
|
107
|
+
bottom: 0;
|
|
108
|
+
background-image: linear-gradient(
|
|
109
|
+
to bottom left,
|
|
110
|
+
transparent calc(50% - 1px),
|
|
111
|
+
var(--fast-tooling-l1-color, #333333),
|
|
112
|
+
transparent calc(50% + 1px)
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
.control-color::after {
|
|
116
|
+
position: absolute;
|
|
117
|
+
content: "";
|
|
118
|
+
left: 0;
|
|
119
|
+
right: 0;
|
|
120
|
+
top: 0;
|
|
121
|
+
bottom: 0;
|
|
122
|
+
background-color: var(--selected-color-value);
|
|
123
|
+
}
|
|
124
|
+
`;
|
package/dist/esm/_docs/design-system/color-explorer/components/color-picker/color-picker.template.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { html, ref } from '@microsoft/fast-element';
|
|
2
|
+
import { TextField } from '@microsoft/fast-foundation';
|
|
3
|
+
/**
|
|
4
|
+
* The template for the color picker component.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export const colorPickerTemplate = context => {
|
|
8
|
+
return html `
|
|
9
|
+
<template
|
|
10
|
+
@focus="${x => x.handleFocus()}"
|
|
11
|
+
@blur="${x => x.handleBlur()}"
|
|
12
|
+
@mousemove="${(x, c) => (x.mouseActive ? x.handleMouseMove(c.event) : null)}"
|
|
13
|
+
@mouseup="${(x, c) => (x.mouseActive ? x.handleMouseUp(c.event) : null)}"
|
|
14
|
+
style="--selected-color-value: ${x => (x.value ? x.value : 'transparent')}"
|
|
15
|
+
>
|
|
16
|
+
<div class="root" part="root">
|
|
17
|
+
<${context.tagFor(TextField)}
|
|
18
|
+
class="root-control"
|
|
19
|
+
part="control"
|
|
20
|
+
id="control"
|
|
21
|
+
@input="${x => x.handleTextInput()}"
|
|
22
|
+
@change="${x => x.handleChange()}"
|
|
23
|
+
?autofocus="${x => x.autofocus}"
|
|
24
|
+
?disabled="${x => x.disabled}"
|
|
25
|
+
placeholder="${x => x.placeholder}"
|
|
26
|
+
?readonly="${x => x.readOnly}"
|
|
27
|
+
?required="${x => x.required}"
|
|
28
|
+
:value="${x => x.value}"
|
|
29
|
+
${ref('control')}
|
|
30
|
+
>
|
|
31
|
+
<div slot="start" class="control-color"></div>
|
|
32
|
+
</${context.tagFor(TextField)}>
|
|
33
|
+
<div class="${x => (x.open ? 'popup__open' : 'popup')}">
|
|
34
|
+
<div class="pickers">
|
|
35
|
+
<div
|
|
36
|
+
class="pickers-saturation"
|
|
37
|
+
style="background-color:${x => x.uiValues.HueCSSColor}"
|
|
38
|
+
@mousedown="${(x, c) => x.handleMouseDown('sv', c.event)}"
|
|
39
|
+
>
|
|
40
|
+
<div
|
|
41
|
+
class="saturation-indicator"
|
|
42
|
+
style="left: ${x => x.uiValues.SatValLeftPos - 2}%; top: ${x => x.uiValues.SatValTopPos - 2}%"
|
|
43
|
+
></div>
|
|
44
|
+
</div>
|
|
45
|
+
<div
|
|
46
|
+
class="pickers-hue"
|
|
47
|
+
@mousedown="${(x, c) => x.handleMouseDown('h', c.event)}"
|
|
48
|
+
>
|
|
49
|
+
<div
|
|
50
|
+
class="hue-indicator"
|
|
51
|
+
style="left: ${x => x.uiValues.HuePosition - 1}%"
|
|
52
|
+
></div>
|
|
53
|
+
</div>
|
|
54
|
+
<div
|
|
55
|
+
class="pickers-alpha"
|
|
56
|
+
@mousedown="${(x, c) => x.handleMouseDown('a', c.event)}"
|
|
57
|
+
>
|
|
58
|
+
<div
|
|
59
|
+
class="alpha-mask"
|
|
60
|
+
style="background-image: linear-gradient(to right, transparent, ${x => x.uiValues.HueCSSColor})"
|
|
61
|
+
></div>
|
|
62
|
+
<div
|
|
63
|
+
class="alpha-indicator"
|
|
64
|
+
style="left: ${x => x.uiValues.AlphaPos - 1}%"
|
|
65
|
+
></div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
<div class="inputs">
|
|
69
|
+
<${context.tagFor(TextField)}
|
|
70
|
+
maxlength="3"
|
|
71
|
+
size="3"
|
|
72
|
+
@input="${(x, c) => x.handleTextValueInput('r', c.event)}"
|
|
73
|
+
:value="${x => Math.round(x.uiValues.RGBColor.r * 255)}"
|
|
74
|
+
>
|
|
75
|
+
<span slot="start">R:</span>
|
|
76
|
+
</${context.tagFor(TextField)}>
|
|
77
|
+
<${context.tagFor(TextField)}
|
|
78
|
+
maxlength="3"
|
|
79
|
+
size="3"
|
|
80
|
+
@input="${(x, c) => x.handleTextValueInput('g', c.event)}"
|
|
81
|
+
:value="${x => Math.round(x.uiValues.RGBColor.g * 255)}"
|
|
82
|
+
>
|
|
83
|
+
<span slot="start">G:</span>
|
|
84
|
+
</${context.tagFor(TextField)}>
|
|
85
|
+
<${context.tagFor(TextField)}
|
|
86
|
+
maxlength="3"
|
|
87
|
+
size="3"
|
|
88
|
+
@input="${(x, c) => x.handleTextValueInput('b', c.event)}"
|
|
89
|
+
:value="${x => Math.round(x.uiValues.RGBColor.b * 255)}"
|
|
90
|
+
>
|
|
91
|
+
<span slot="start">B:</span>
|
|
92
|
+
</${context.tagFor(TextField)}>
|
|
93
|
+
<${context.tagFor(TextField)}
|
|
94
|
+
maxlength="3"
|
|
95
|
+
size="3"
|
|
96
|
+
@input="${(x, c) => x.handleTextValueInput('h', c.event)}"
|
|
97
|
+
:value="${x => Math.round(x.uiValues.HSVColor.h)}"
|
|
98
|
+
>
|
|
99
|
+
<span slot="start">H:</span>
|
|
100
|
+
</${context.tagFor(TextField)}>
|
|
101
|
+
<${context.tagFor(TextField)}
|
|
102
|
+
maxlength="3"
|
|
103
|
+
size="3"
|
|
104
|
+
@input="${(x, c) => x.handleTextValueInput('s', c.event)}"
|
|
105
|
+
:value="${x => Math.round(x.uiValues.HSVColor.s * 100)}"
|
|
106
|
+
>
|
|
107
|
+
<span slot="start">S:</span>
|
|
108
|
+
</${context.tagFor(TextField)}>
|
|
109
|
+
<${context.tagFor(TextField)}
|
|
110
|
+
maxlength="3"
|
|
111
|
+
size="3"
|
|
112
|
+
@input="${(x, c) => x.handleTextValueInput('v', c.event)}"
|
|
113
|
+
:value="${x => Math.round(x.uiValues.HSVColor.v * 100)}"
|
|
114
|
+
>
|
|
115
|
+
<span slot="start">V:</span>
|
|
116
|
+
</${context.tagFor(TextField)}>
|
|
117
|
+
<${context.tagFor(TextField)}
|
|
118
|
+
maxlength="3"
|
|
119
|
+
size="3"
|
|
120
|
+
@input="${(x, c) => x.handleTextValueInput('a', c.event)}"
|
|
121
|
+
:value="${x => Math.round(x.uiValues.RGBColor.a * 100)}"
|
|
122
|
+
>
|
|
123
|
+
<span slot="start">A:</span>
|
|
124
|
+
</${context.tagFor(TextField)}>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
129
|
+
`;
|
|
130
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ColorPicker } from './color-picker';
|
|
2
|
+
import { colorPickerTemplate as template } from './color-picker.template';
|
|
3
|
+
import { colorPickerStyles as styles } from './color-picker.styles';
|
|
4
|
+
/**
|
|
5
|
+
* A web component used for updating color values.
|
|
6
|
+
*
|
|
7
|
+
* @alpha
|
|
8
|
+
* @remarks
|
|
9
|
+
* HTML Element: \<color-picker\>
|
|
10
|
+
*/
|
|
11
|
+
export const fastToolingColorPicker = ColorPicker.compose({
|
|
12
|
+
baseName: 'color-picker',
|
|
13
|
+
template,
|
|
14
|
+
styles,
|
|
15
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { observable } from '@microsoft/fast-element';
|
|
3
|
+
import { FoundationElement } from '@microsoft/fast-foundation';
|
|
4
|
+
export class ControlPane extends FoundationElement {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.showOnlyLayerBackgrounds = true;
|
|
8
|
+
}
|
|
9
|
+
updateFormValue(field, value) {
|
|
10
|
+
this.$emit('formvaluechange', { field: field, value: value });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
__decorate([
|
|
14
|
+
observable
|
|
15
|
+
], ControlPane.prototype, "componentType", void 0);
|
|
16
|
+
__decorate([
|
|
17
|
+
observable
|
|
18
|
+
], ControlPane.prototype, "accentColor", void 0);
|
|
19
|
+
__decorate([
|
|
20
|
+
observable
|
|
21
|
+
], ControlPane.prototype, "neutralColor", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
observable
|
|
24
|
+
], ControlPane.prototype, "showOnlyLayerBackgrounds", void 0);
|
package/dist/esm/_docs/design-system/color-explorer/components/control-pane/control-pane.styles.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { css } from "@microsoft/fast-element";
|
|
2
|
+
import { display } from "@microsoft/fast-foundation";
|
|
3
|
+
import { typeRampPlus1FontSize, typeRampPlus1LineHeight } from "../../../../../index-rollup";
|
|
4
|
+
export const controlPaneStyles = css `
|
|
5
|
+
${display("flex")} :host {
|
|
6
|
+
flex: 0 1 auto;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
gap: 24px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.title {
|
|
12
|
+
font-size: ${typeRampPlus1FontSize};
|
|
13
|
+
line-height: ${typeRampPlus1LineHeight};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fluent-radio-group::part(positioning-region) {
|
|
17
|
+
gap: 8px;
|
|
18
|
+
}
|
|
19
|
+
`;
|
package/dist/esm/_docs/design-system/color-explorer/components/control-pane/control-pane.template.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { html, repeat } from '@microsoft/fast-element';
|
|
2
|
+
import { ComponentTypes } from '../../component-types';
|
|
3
|
+
function titleCase(str) {
|
|
4
|
+
return str.split('').reduce((accumulated, value, index) => {
|
|
5
|
+
return accumulated.concat(index === 0 ? value.toUpperCase() : value);
|
|
6
|
+
}, '');
|
|
7
|
+
}
|
|
8
|
+
export const controlPaneTemplate = html `
|
|
9
|
+
<template>
|
|
10
|
+
<p class="title">Settings</p>
|
|
11
|
+
<fluent-radio-group
|
|
12
|
+
name="componentType"
|
|
13
|
+
orientation="vertical"
|
|
14
|
+
@change="${(x, c) => {
|
|
15
|
+
x.updateFormValue('componentType', c.event.target.value);
|
|
16
|
+
}}"
|
|
17
|
+
>
|
|
18
|
+
<label slot="label">Component type</label>
|
|
19
|
+
${repeat(x => Object.keys(ComponentTypes), html `
|
|
20
|
+
<fluent-radio value="${x => x}" ?checked="${(x, c) => c.parent.componentType === x}">
|
|
21
|
+
${x => titleCase(x)}
|
|
22
|
+
</fluent-radio>
|
|
23
|
+
`)}
|
|
24
|
+
</fluent-radio-group>
|
|
25
|
+
<div>
|
|
26
|
+
<label>Neutral base color</label>
|
|
27
|
+
<fast-tooling-color-picker
|
|
28
|
+
value="${x => x.neutralColor}"
|
|
29
|
+
@change="${(x, c) => {
|
|
30
|
+
x.updateFormValue('neutralColor', c.event.target.value);
|
|
31
|
+
}}"
|
|
32
|
+
></fast-tooling-color-picker>
|
|
33
|
+
</div>
|
|
34
|
+
<fluent-checkbox
|
|
35
|
+
checked="${x => x.showOnlyLayerBackgrounds}"
|
|
36
|
+
@change="${(x, c) => {
|
|
37
|
+
x.updateFormValue('showOnlyLayerBackgrounds', c.event.target.checked);
|
|
38
|
+
}}"
|
|
39
|
+
>
|
|
40
|
+
Show layer backgrounds only
|
|
41
|
+
</fluent-checkbox>
|
|
42
|
+
<div>
|
|
43
|
+
<label>Accent base color</label>
|
|
44
|
+
<fast-tooling-color-picker
|
|
45
|
+
value="${x => x.accentColor}"
|
|
46
|
+
@change="${(x, c) => {
|
|
47
|
+
x.updateFormValue('accentColor', c.event.target.value);
|
|
48
|
+
}}"
|
|
49
|
+
></fast-tooling-color-picker>
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|
|
52
|
+
`;
|