From fcfdb8481a14f4add1b4de120c9feb1b1400e6df Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Tue, 4 Oct 2022 17:20:40 +0200 Subject: [PATCH 01/25] maint(pat-toggle): Add alias attribute for attr to toggle an attribute. --- src/pat/toggle/documentation.md | 22 +++++++++++++++++++++- src/pat/toggle/toggle.js | 2 ++ src/pat/toggle/toggle.test.js | 22 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/pat/toggle/documentation.md b/src/pat/toggle/documentation.md index 4cf6246e4..8dc32dff7 100644 --- a/src/pat/toggle/documentation.md +++ b/src/pat/toggle/documentation.md @@ -8,7 +8,12 @@ For instance to show or hide a sidebar with a CSS class on the body tag. The _toggle_ pattern can be used to toggle attribute values for objects. It is most commonly used to toggle a CSS class. - Start working + Start working
Working…
@@ -67,3 +72,18 @@ The possible values for the `store` parameter are: - `none`: do not remember the toggle state (default). - `local`: remember the state as part of the local storage. - `session`: remember the status as part of the session storage. + + +### Options reference + +You can customise the behaviour of a switches through options in the +`data-pat-toggle` attribute. + +| Property | Default value | Values | Description | Type | +| ---------- | ------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | +| `selector` | | | CSS selector matching elements where a class or an attribute should be toggled. | String | +| `value` |   |   | One or more space seperated CSS class names to toggle on the element. Can only be used with `attr` set to class, which is the default. | String | +| `event` | `click` | | A JavaScript event which triggers the toggler. The default is to listen to `click` events. | String | +| `attr` | `class` | | The attribute which should be toggled. In case of the default `class`, class names are added or removed. In case of any other attribute the attribute as added or removed. | String | +| `store` | `none` | `none` `session` `local` | How to store the state of a toggle. `none` does not remember the toggle state, `local` stores the state as part of the local storage and `session` stores the status as part of the session storage. | Mutually exclusive | + diff --git a/src/pat/toggle/toggle.js b/src/pat/toggle/toggle.js index 38ccc0b87..735d4638a 100644 --- a/src/pat/toggle/toggle.js +++ b/src/pat/toggle/toggle.js @@ -19,6 +19,8 @@ parser.addArgument("attr", "class"); parser.addArgument("value"); parser.addArgument("store", "none", ["none", "session", "local"]); +parser.addAlias("attribute", "attr"); + export function ClassToggler(values) { this.values = values.slice(0); if (this.values.length > 1) this.values.push(values[0]); diff --git a/src/pat/toggle/toggle.test.js b/src/pat/toggle/toggle.test.js index b0c36ef84..d7b408f70 100644 --- a/src/pat/toggle/toggle.test.js +++ b/src/pat/toggle/toggle.test.js @@ -175,6 +175,16 @@ describe("Pattern implementation", function () { store: "none", }); }); + + it("1.6 - Accept attribute as an alias to attr.", function () { + const instance = new Pattern(document.createElement("div")); + const validated = instance._validateOptions([ + { attribute: "disabled", selector: "input" }, + ]); + expect(validated.length).toEqual(1); + expect(validated[0].attribute).toEqual("disabled"); + expect(validated[0].selector).toEqual("input"); + }); }); describe("2 - When clicking on a toggle", function () { @@ -226,6 +236,18 @@ describe("Pattern implementation", function () { await utils.timeout(1); expect(victims[0].disabled).toBe(false); }); + + it("2.3 - attributes are updated - use the alias", async function () { + var $trigger = $(trigger); + trigger.dataset.patToggle = ".victim; attribute: disabled"; + new Pattern($trigger); + $trigger.click(); + await utils.timeout(1); + expect(victims[0].disabled).toBe(true); + $trigger.click(); + await utils.timeout(1); + expect(victims[0].disabled).toBe(false); + }); }); describe("3 - Toggle event triggers", function () { From 752036f9848172a2b74f6070c5be71e12a0ca046 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 5 Oct 2022 14:17:27 +0200 Subject: [PATCH 02/25] feat(pat-date-picker): Add placeholder support for styled behavior. /cc @cornae This fixes the following two issues: Fixes: https://github.com/Patternslib/Patterns/issues/837 Fixes: https://github.com/quaive/ploneintranet.prototype/issues/1289 --- src/pat/date-picker/date-picker.js | 34 +++++++--- src/pat/date-picker/date-picker.test.js | 82 +++++++++++++++++++------ src/pat/date-picker/index.html | 8 +++ 3 files changed, 96 insertions(+), 28 deletions(-) diff --git a/src/pat/date-picker/date-picker.js b/src/pat/date-picker/date-picker.js index 184c98144..69574c84c 100644 --- a/src/pat/date-picker/date-picker.js +++ b/src/pat/date-picker/date-picker.js @@ -95,7 +95,7 @@ export default Base.extend({ ); } - let display_el_pat; + let pat_display_time; if (this.options.outputFormat) { const PatDisplayTime = (await import("../display-time/display-time")).default; // prettier-ignore const display_time_config = { format: this.format }; @@ -105,23 +105,39 @@ export default Base.extend({ if (this.options.locale) { display_time_config.locale = this.options.locale; } - display_el_pat = new PatDisplayTime(display_el, display_time_config); - } else { + pat_display_time = new PatDisplayTime(display_el, display_time_config); + } else if (this.el.value) { display_el.textContent = el.value; } - $(display_el).on("init.display-time.patterns", () => - this.add_clear_button(display_el) - ); + // Add the additional elements "clear button" and placeholder to + // the `