From 3126c50baa9ff35e9bf9cdfad5f7e262b1ed3420 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Mon, 29 Jul 2024 14:07:06 +0800 Subject: [PATCH] DEV: Update member access wizard step to use toggle group (#28013) We want to change the design of the "member experience" step of the wizard from using checkbox switches to using radio toggle groups. --- .../static/wizard/components/fields/index.js | 2 + .../static/wizard/components/fields/radio.gjs | 72 +++++++++++++++++++ .../static/wizard/components/wizard-field.gjs | 3 +- app/assets/stylesheets/wizard.scss | 55 +++++++++++++- config/locales/server.en.yml | 28 ++++++-- lib/wizard/builder.rb | 45 ++++++------ lib/wizard/step.rb | 1 + spec/lib/wizard/step_updater_spec.rb | 12 ++-- spec/lib/wizard/wizard_builder_spec.rb | 10 +-- spec/serializers/wizard_serializer_spec.rb | 6 +- spec/system/page_objects/pages/wizard.rb | 8 +++ spec/system/wizard_spec.rb | 28 ++++++++ 12 files changed, 221 insertions(+), 49 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/static/wizard/components/fields/radio.gjs diff --git a/app/assets/javascripts/discourse/app/static/wizard/components/fields/index.js b/app/assets/javascripts/discourse/app/static/wizard/components/fields/index.js index deb2152be4e..6127a0281dc 100644 --- a/app/assets/javascripts/discourse/app/static/wizard/components/fields/index.js +++ b/app/assets/javascripts/discourse/app/static/wizard/components/fields/index.js @@ -2,6 +2,7 @@ import Checkbox from "./checkbox"; import Checkboxes from "./checkboxes"; import Dropdown from "./dropdown"; import Image from "./image"; +import Radio from "./radio"; import StylingPreview from "./styling-preview"; import Text from "./text"; @@ -12,4 +13,5 @@ export default { dropdown: Dropdown, image: Image, text: Text, + radio: Radio, }; diff --git a/app/assets/javascripts/discourse/app/static/wizard/components/fields/radio.gjs b/app/assets/javascripts/discourse/app/static/wizard/components/fields/radio.gjs new file mode 100644 index 00000000000..51f6db63547 --- /dev/null +++ b/app/assets/javascripts/discourse/app/static/wizard/components/fields/radio.gjs @@ -0,0 +1,72 @@ +import Component from "@glimmer/component"; +import { hash } from "@ember/helper"; +import { on } from "@ember/modifier"; +import { action, set } from "@ember/object"; +import PluginOutlet from "discourse/components/plugin-outlet"; +import concatClass from "discourse/helpers/concat-class"; +import withEventValue from "discourse/helpers/with-event-value"; +import icon from "discourse-common/helpers/d-icon"; + +export default class Radio extends Component { + constructor() { + super(...arguments); + + this._setSelected(); + } + + get field() { + return this.args.field; + } + + @action + selectionChanged(input) { + this.field.value = input; + this._setSelected(); + } + + _setSelected() { + for (let choice of this.field.choices) { + set(choice, "selected", this.field.value === choice.id); + } + } + + +} diff --git a/app/assets/javascripts/discourse/app/static/wizard/components/wizard-field.gjs b/app/assets/javascripts/discourse/app/static/wizard/components/wizard-field.gjs index a2f96fddfe7..b2bd553a47d 100644 --- a/app/assets/javascripts/discourse/app/static/wizard/components/wizard-field.gjs +++ b/app/assets/javascripts/discourse/app/static/wizard/components/wizard-field.gjs @@ -3,6 +3,7 @@ import { assert } from "@ember/debug"; import { hash } from "@ember/helper"; import { dasherize } from "@ember/string"; import { htmlSafe } from "@ember/template"; +import { or } from "truth-helpers"; import PluginOutlet from "discourse/components/plugin-outlet"; import fields from "./fields"; @@ -42,7 +43,7 @@ export default class WizardFieldComponent extends Component {