@openproject/primer-view-components 0.92.0 → 0.93.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.
@@ -0,0 +1 @@
1
+ .ColorField{display:block}.ColorField .ColorField-wrap .FormControl-input{padding-inline-start:calc(var(--base-size-4) + var(--base-size-24) + var(--base-size-8))}.ColorField .ColorField-swatch{position:absolute;inset-block:0;inset-inline-start:var(--base-size-4);display:flex;align-items:center}.ColorField .ColorField-picker{width:var(--base-size-24);height:var(--base-size-24);padding:0;cursor:pointer;background-color:var(--bgColor-muted);border:0;border-radius:var(--borderRadius-small);outline:var(--borderWidth-thin) solid var(--borderColor-translucent);outline-offset:calc(var(--borderWidth-thin)*-1);appearance:none;forced-color-adjust:none}:is(.ColorField .ColorField-picker):disabled{cursor:default}:is(.ColorField .ColorField-picker):focus-visible{outline:2px solid var(--focus-outlineColor);outline-offset:-2px;box-shadow:none}:is(.ColorField .ColorField-picker)::-webkit-color-swatch-wrapper{padding:0}:is(.ColorField .ColorField-picker)::-webkit-color-swatch{border:0;border-radius:var(--borderRadius-small)}:is(.ColorField .ColorField-picker)::-moz-color-swatch{border:0;border-radius:var(--borderRadius-small)}.ColorField[data-blank] .ColorField-picker{outline-style:dashed}.ColorField[data-empty] .ColorField-picker::-webkit-color-swatch{opacity:0}.ColorField[data-empty] .ColorField-picker::-moz-color-swatch{opacity:0}.ColorField:not(:defined) .ColorField-picker:disabled{opacity:1}
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "open_project/color_field",
3
+ "selectors": [
4
+ ".ColorField",
5
+ ".ColorField .ColorField-wrap .FormControl-input",
6
+ ".ColorField .ColorField-swatch",
7
+ ".ColorField .ColorField-picker",
8
+ ":is(.ColorField .ColorField-picker):disabled",
9
+ ":is(.ColorField .ColorField-picker):focus-visible",
10
+ ":is(.ColorField .ColorField-picker)::-webkit-color-swatch-wrapper",
11
+ ":is(.ColorField .ColorField-picker)::-webkit-color-swatch",
12
+ ":is(.ColorField .ColorField-picker)::-moz-color-swatch",
13
+ ".ColorField[data-blank] .ColorField-picker",
14
+ ".ColorField[data-empty] .ColorField-picker::-webkit-color-swatch",
15
+ ".ColorField[data-empty] .ColorField-picker::-moz-color-swatch",
16
+ ".ColorField:not(:defined) .ColorField-picker:disabled"
17
+ ]
18
+ }
@@ -23,6 +23,7 @@ import './alpha/tab_container';
23
23
  import '../../lib/primer/forms/primer_multi_input';
24
24
  import '../../lib/primer/forms/primer_text_field';
25
25
  import '../../lib/primer/forms/primer_text_area';
26
+ import '../../lib/primer/forms/primer_color_input';
26
27
  import '../../lib/primer/forms/toggle_switch_input';
27
28
  import './alpha/action_menu/action_menu_element';
28
29
  import './alpha/select_panel_element';
@@ -23,6 +23,7 @@ import './alpha/tab_container';
23
23
  import '../../lib/primer/forms/primer_multi_input';
24
24
  import '../../lib/primer/forms/primer_text_field';
25
25
  import '../../lib/primer/forms/primer_text_area';
26
+ import '../../lib/primer/forms/primer_color_input';
26
27
  import '../../lib/primer/forms/toggle_switch_input';
27
28
  import './alpha/action_menu/action_menu_element';
28
29
  import './alpha/select_panel_element';
@@ -0,0 +1,17 @@
1
+ export declare function parseHex(text: string): string | null;
2
+ export declare class PrimerColorInputElement extends HTMLElement {
3
+ #private;
4
+ inputElement: HTMLInputElement;
5
+ pickerElement: HTMLInputElement;
6
+ blank: boolean;
7
+ empty: boolean;
8
+ connectedCallback(): void;
9
+ disconnectedCallback(): void;
10
+ private syncDisabled;
11
+ syncPicker(): void;
12
+ normalize(): void;
13
+ trimPaste(event: ClipboardEvent): void;
14
+ syncInput(event: Event): void;
15
+ commit(event: Event): void;
16
+ sync(): void;
17
+ }
@@ -0,0 +1,138 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
13
+ if (kind === "m") throw new TypeError("Private method is not writable");
14
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
15
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
16
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
+ };
18
+ var _PrimerColorInputElement_abortController, _PrimerColorInputElement_observer;
19
+ import { attr, controller, target } from '@github/catalyst';
20
+ const HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
21
+ // Returns the canonical uppercase `#RRGGBB` form of the given text, or null
22
+ // if it is not a three- or six-digit hex color.
23
+ export function parseHex(text) {
24
+ const match = HEX_PATTERN.exec(text.trim());
25
+ if (!match)
26
+ return null;
27
+ let digits = match[1];
28
+ if (digits.length === 3)
29
+ digits = digits.replace(/./g, '$&$&');
30
+ return `#${digits.toUpperCase()}`;
31
+ }
32
+ let PrimerColorInputElement = class PrimerColorInputElement extends HTMLElement {
33
+ constructor() {
34
+ super(...arguments);
35
+ // The text input is empty.
36
+ this.blank = false;
37
+ // There is no color to show in the swatch.
38
+ this.empty = false;
39
+ _PrimerColorInputElement_abortController.set(this, null);
40
+ _PrimerColorInputElement_observer.set(this, null);
41
+ }
42
+ connectedCallback() {
43
+ __classPrivateFieldGet(this, _PrimerColorInputElement_abortController, "f")?.abort();
44
+ const { signal } = (__classPrivateFieldSet(this, _PrimerColorInputElement_abortController, new AbortController(), "f"));
45
+ this.syncDisabled();
46
+ this.sync();
47
+ // The server always renders the picker disabled. Whatever rewrites
48
+ // attributes without reconnecting this element, a Turbo morph for one,
49
+ // puts that back, so the rule is re-applied on every such change.
50
+ __classPrivateFieldGet(this, _PrimerColorInputElement_observer, "f")?.disconnect();
51
+ __classPrivateFieldSet(this, _PrimerColorInputElement_observer, new MutationObserver(() => this.syncDisabled()), "f");
52
+ __classPrivateFieldGet(this, _PrimerColorInputElement_observer, "f").observe(this, { attributes: true, attributeFilter: ['disabled', 'readonly'], subtree: true });
53
+ // The form is outside this element's subtree, so data-action cannot
54
+ // reach it. Reset restores the text value after the event, hence the tick.
55
+ this.inputElement.form?.addEventListener('reset', () => setTimeout(() => this.sync()), { signal });
56
+ }
57
+ disconnectedCallback() {
58
+ __classPrivateFieldGet(this, _PrimerColorInputElement_abortController, "f")?.abort();
59
+ __classPrivateFieldGet(this, _PrimerColorInputElement_observer, "f")?.disconnect();
60
+ }
61
+ // The picker is operable only while its value can reach the submitted text
62
+ // input and that input accepts edits.
63
+ syncDisabled() {
64
+ const disabled = this.inputElement.disabled || this.inputElement.readOnly;
65
+ // Assigning the same value again would still rewrite the attribute and
66
+ // wake the observer, which would then never settle.
67
+ if (this.pickerElement.disabled !== disabled)
68
+ this.pickerElement.disabled = disabled;
69
+ }
70
+ // Text → picker. Bound to `input` on the text input, so the swatch follows
71
+ // every keystroke: text that is not a whole color yet shows none. The
72
+ // picker itself has no empty value and keeps the last color to open on.
73
+ syncPicker() {
74
+ const text = this.inputElement.value.trim();
75
+ const color = parseHex(text);
76
+ this.blank = text === '';
77
+ this.empty = color === null;
78
+ if (color)
79
+ this.pickerElement.value = color.toLowerCase();
80
+ }
81
+ // Bound to `change` on the text input.
82
+ normalize() {
83
+ const color = parseHex(this.inputElement.value);
84
+ if (color)
85
+ this.inputElement.value = color;
86
+ }
87
+ // Bound to `paste` on the text input. The browser cuts a paste to the
88
+ // input's `maxlength` first, so padding around a copied color would push
89
+ // its last digits out. The padding is dropped and the rest inserted as an
90
+ // edit of the user's own, which keeps undo, `maxlength` and read-only
91
+ // intact and still ends in a `change` event.
92
+ trimPaste(event) {
93
+ const text = event.clipboardData?.getData('text/plain') ?? '';
94
+ const trimmed = text.trim();
95
+ if (trimmed === text)
96
+ return;
97
+ event.preventDefault();
98
+ document.execCommand('insertText', false, trimmed);
99
+ }
100
+ // Picker → text. Bound to `input` on the picker. The picker's own event
101
+ // stops here: the one forwarded from the text input stands in for it, and
102
+ // listeners further up would otherwise hear of each pick twice.
103
+ syncInput(event) {
104
+ /* eslint-disable-next-line no-restricted-syntax */
105
+ event.stopPropagation();
106
+ this.inputElement.value = this.pickerElement.value.toUpperCase();
107
+ this.inputElement.dispatchEvent(new Event('input', { bubbles: true }));
108
+ }
109
+ // Bound to `change` on the picker, whose own event stops here as well.
110
+ commit(event) {
111
+ /* eslint-disable-next-line no-restricted-syntax */
112
+ event.stopPropagation();
113
+ this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
114
+ }
115
+ // Resynchronises from the text input's current value. Call this after
116
+ // setting the value from script, which fires no event.
117
+ sync() {
118
+ this.syncPicker();
119
+ }
120
+ };
121
+ _PrimerColorInputElement_abortController = new WeakMap();
122
+ _PrimerColorInputElement_observer = new WeakMap();
123
+ __decorate([
124
+ target
125
+ ], PrimerColorInputElement.prototype, "inputElement", void 0);
126
+ __decorate([
127
+ target
128
+ ], PrimerColorInputElement.prototype, "pickerElement", void 0);
129
+ __decorate([
130
+ attr
131
+ ], PrimerColorInputElement.prototype, "blank", void 0);
132
+ __decorate([
133
+ attr
134
+ ], PrimerColorInputElement.prototype, "empty", void 0);
135
+ PrimerColorInputElement = __decorate([
136
+ controller('primer-color-input')
137
+ ], PrimerColorInputElement);
138
+ export { PrimerColorInputElement };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openproject/primer-view-components",
3
- "version": "0.92.0",
3
+ "version": "0.93.0",
4
4
  "description": "ViewComponents of the Primer Design System for OpenProject",
5
5
  "main": "app/assets/javascripts/primer_view_components.js",
6
6
  "module": "app/components/primer/primer.js",
@@ -5973,6 +5973,160 @@
5973
5973
  }
5974
5974
  ]
5975
5975
  },
5976
+ {
5977
+ "component": "OpenProject::ColorField",
5978
+ "status": "open_project",
5979
+ "a11y_reviewed": false,
5980
+ "short_name": "OpenProjectColorField",
5981
+ "source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/color_field.rb",
5982
+ "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/color_field/default/",
5983
+ "parameters": [
5984
+ {
5985
+ "name": "size",
5986
+ "type": "Symbol",
5987
+ "default": "N/A",
5988
+ "description": "The size of the field. One of `:large`, `:medium`, or `:small`."
5989
+ },
5990
+ {
5991
+ "name": "full_width",
5992
+ "type": "Boolean",
5993
+ "default": "N/A",
5994
+ "description": "When set to `true`, the field will take up all the horizontal space allowed by its container. Defaults to `true`."
5995
+ },
5996
+ {
5997
+ "name": "name",
5998
+ "type": "String",
5999
+ "default": "N/A",
6000
+ "description": "Value for the HTML name attribute."
6001
+ },
6002
+ {
6003
+ "name": "id",
6004
+ "type": "String",
6005
+ "default": "N/A",
6006
+ "description": "Value for the HTML id attribute."
6007
+ },
6008
+ {
6009
+ "name": "class",
6010
+ "type": "String",
6011
+ "default": "N/A",
6012
+ "description": "CSS classes to include in the input's HTML `class` attribute. Exists for compatibility with Rails form builders."
6013
+ },
6014
+ {
6015
+ "name": "classes",
6016
+ "type": "Array",
6017
+ "default": "N/A",
6018
+ "description": "CSS classes to include in the input's HTML `class` attribute. Combined with the `:class` argument. The list may contain strings, hashes, or `nil` values, and is automatically cleaned up by Primer's [`class_name` helper](https://github.com/primer/view_components/blob/c9cb95c98fee3e2e27f4a10683f555e22285e7f1/app/lib/primer/class_name_helper.rb) (`nils`, falsy entries, and blank strings are ignored)."
6019
+ },
6020
+ {
6021
+ "name": "caption",
6022
+ "type": "String",
6023
+ "default": "N/A",
6024
+ "description": "A string describing the field and what sorts of input it expects. Displayed below the input."
6025
+ },
6026
+ {
6027
+ "name": "label",
6028
+ "type": "String",
6029
+ "default": "N/A",
6030
+ "description": "Label text displayed above the input."
6031
+ },
6032
+ {
6033
+ "name": "visually_hide_label",
6034
+ "type": "Boolean",
6035
+ "default": "N/A",
6036
+ "description": "When set to `true`, hides the label. Although the label will be hidden visually, it will still be visible to screen readers."
6037
+ },
6038
+ {
6039
+ "name": "disabled",
6040
+ "type": "Boolean",
6041
+ "default": "N/A",
6042
+ "description": "When set to `true`, the input will not accept keyboard or mouse input."
6043
+ },
6044
+ {
6045
+ "name": "hidden",
6046
+ "type": "Boolean",
6047
+ "default": "N/A",
6048
+ "description": "When set to `true`, visually hides the field."
6049
+ },
6050
+ {
6051
+ "name": "invalid",
6052
+ "type": "Boolean",
6053
+ "default": "N/A",
6054
+ "description": "If set to `true`, the input will be rendered with a red border. Implied if `validation_message` is truthy. This option is set to `true` automatically if the model object associated with the form reports that the input is invalid via Rails validations. It is provided for cases where the form does not have an associated model. If the input is invalid as determined by Rails validations, setting `invalid` to `false` will have no effect."
6055
+ },
6056
+ {
6057
+ "name": "validation_message",
6058
+ "type": "String",
6059
+ "default": "N/A",
6060
+ "description": "A string displayed between the caption and the input indicating the input's contents are invalid. This option is, by default, set to the first Rails validation message for the input (assuming the form is associated with a model object). Use `validation_message` to override the default or to provide a validation message in case there is no associated model object."
6061
+ },
6062
+ {
6063
+ "name": "label_arguments",
6064
+ "type": "Hash",
6065
+ "default": "N/A",
6066
+ "description": "Attributes that will be passed to Rails' `builder.label` method. These can be HTML attributes or any of the other label options Rails supports. They will appear as HTML attributes on the `<label>` tag."
6067
+ },
6068
+ {
6069
+ "name": "scope_name_to_model",
6070
+ "type": "Boolean",
6071
+ "default": "N/A",
6072
+ "description": "Default `true`. When set to `false`, prevents the model name from prefixing the field name. For example, if the field name is `my_field`, Rails will normally emit an HTML name attribute of `model[my_field]`. Setting `scope_name_to_model` to `false` will cause Rails to emit `my_field` instead."
6073
+ },
6074
+ {
6075
+ "name": "scope_id_to_model",
6076
+ "type": "Boolean",
6077
+ "default": "N/A",
6078
+ "description": "Default `true`. When set to `false`, prevents the model name from prefixing the field ID. For example, if the field name is `my_field`, Rails will normally emit an HTML ID attribute of `model_my_field`. Setting `scope_id_to_model` to `false` will cause Rails to emit `my_field` instead."
6079
+ },
6080
+ {
6081
+ "name": "required",
6082
+ "type": "Boolean",
6083
+ "default": "N/A",
6084
+ "description": "Default `false`. When set to `true`, causes an asterisk (*) to appear next to the field's label indicating it is a required field. Note that this option explicitly does _not_ add a `required` HTML attribute. Doing so would enable native browser validations, which are inaccessible and inconsistent with the Primer design system."
6085
+ },
6086
+ {
6087
+ "name": "aria",
6088
+ "type": "Hash",
6089
+ "default": "N/A",
6090
+ "description": "Key/value pairs that represent Aria attributes and their values. Eg. `aria: { current: true }` becomes `aria-current=\"true\"`."
6091
+ },
6092
+ {
6093
+ "name": "data",
6094
+ "type": "Hash",
6095
+ "default": "N/A",
6096
+ "description": "Key/value pairs that represent data attributes and their values. Eg. `data: { foo: \"bar\" }` becomes `data-foo=\"bar\"`."
6097
+ },
6098
+ {
6099
+ "name": "system_arguments",
6100
+ "type": "Hash",
6101
+ "default": "N/A",
6102
+ "description": "A hash of attributes passed to the underlying Rails builder methods. These options may mean something special depending on the type of input, otherwise they are emitted as HTML attributes. See the [Rails documentation](https://guides.rubyonrails.org/form_helpers.html) for more information. In addition, the usual Primer utility arguments are accepted in system arguments. For example, passing `mt: 2` will add the `mt-2` class to the input. See the Primer system arguments docs for details."
6103
+ },
6104
+ {
6105
+ "name": "input_width",
6106
+ "type": "Symbol",
6107
+ "default": "N/A",
6108
+ "description": "The width of the field. One of `:auto`, `:large`, `:medium`, `:small`, `:xlarge`, `:xsmall`, or `:xxlarge`."
6109
+ },
6110
+ {
6111
+ "name": "maxlength",
6112
+ "type": "Integer",
6113
+ "default": "N/A",
6114
+ "description": "Maximum number of characters the text input accepts. Defaults to 7, the length of `#RRGGBB`."
6115
+ },
6116
+ {
6117
+ "name": "placeholder",
6118
+ "type": "String",
6119
+ "default": "N/A",
6120
+ "description": "Placeholder text. It is not previewed in the swatch, which stays empty while the field is blank."
6121
+ },
6122
+ {
6123
+ "name": "picker_label",
6124
+ "type": "String",
6125
+ "default": "N/A",
6126
+ "description": "Accessible name of the native color picker. Defaults to `I18n.t(\"color_field.picker_label\", label: label)`, or to `I18n.t(\"color_field.picker_label_generic\")` when there is no label."
6127
+ }
6128
+ ]
6129
+ },
5976
6130
  {
5977
6131
  "component": "OpenProject::DangerDialog",
5978
6132
  "status": "open_project",
@@ -146,6 +146,7 @@
146
146
  "Primer::OpenProject::BorderGrid": "",
147
147
  "Primer::OpenProject::BorderGrid::Cell": "",
148
148
  "Primer::OpenProject::CollapsibleSection": "",
149
+ "Primer::OpenProject::ColorField": "",
149
150
  "Primer::OpenProject::DangerDialog": "",
150
151
  "Primer::OpenProject::DangerDialog::ConfirmationCheckBox": "",
151
152
  "Primer::OpenProject::DangerDialog::FormWrapper": "",
@@ -265,6 +265,9 @@
265
265
  "CollapsibleSection--triggerArea": [
266
266
  "Primer::OpenProject::CollapsibleSection"
267
267
  ],
268
+ "ColorField": [
269
+ "Primer::OpenProject::ColorField"
270
+ ],
268
271
  "Counter": [
269
272
  "Primer::Beta::Counter"
270
273
  ],
@@ -122,6 +122,10 @@ module.exports = new Set([
122
122
  'CollapsibleHeader-title-line',
123
123
  'CollapsibleHeader-triggerArea',
124
124
  'CollapsibleSection--triggerArea',
125
+ 'ColorField',
126
+ 'ColorField-picker',
127
+ 'ColorField-swatch',
128
+ 'ColorField-wrap',
125
129
  'Counter',
126
130
  'Counter--primary',
127
131
  'Counter--secondary',
@@ -122,6 +122,10 @@ const classNames = new Set([
122
122
  'CollapsibleHeader-title-line',
123
123
  'CollapsibleHeader-triggerArea',
124
124
  'CollapsibleSection--triggerArea',
125
+ 'ColorField',
126
+ 'ColorField-picker',
127
+ 'ColorField-swatch',
128
+ 'ColorField-wrap',
125
129
  'Counter',
126
130
  'Counter--primary',
127
131
  'Counter--secondary',
@@ -1759,6 +1759,9 @@
1759
1759
  "span"
1760
1760
  ]
1761
1761
  },
1762
+ "Primer::OpenProject::ColorField": {
1763
+ "GeneratedSlotMethods": "Primer::OpenProject::ColorField::GeneratedSlotMethods"
1764
+ },
1762
1765
  "Primer::OpenProject::DangerDialog": {
1763
1766
  "ConfirmationCheckBox": "Primer::OpenProject::DangerDialog::ConfirmationCheckBox",
1764
1767
  "FormWrapper": "Primer::OpenProject::DangerDialog::FormWrapper",