Skip to content

A platform for community discussion. Free, open, simple.

UX: new checkbox design (#38967)

chapoi20405dce45fb
diff --git a/app/assets/stylesheets/common/form-kit/_control-checkbox-upcoming-changes.scss b/app/assets/stylesheets/common/form-kit/_control-checkbox-upcoming-changes.scss
new file mode 100644
index 00000000000..46a4d5c97c1
--- /dev/null
+++ b/app/assets/stylesheets/common/form-kit/_control-checkbox-upcoming-changes.scss
@@ -0,0 +1,92 @@
+.uc-enable-new-checkbox-style {
+ .form-kit {
+ &__control-checkbox {
+ /* hide native checkbox */
+ position: absolute;
+ opacity: 0;
+
+ &-label {
+ display: flex;
+ gap: 0.75em;
+ margin: 0;
+ font-weight: normal !important;
+ color: var(--primary);
+ font-size: var(--font-down-1-rem);
+ cursor: pointer;
+
+ .form-kit__field[data-disabled] & {
+ cursor: not-allowed;
+ }
+ }
+ }
+
+ &__control-checkbox-checkmark {
+ /* custom box */
+ width: 1.25em;
+ height: 1.25em;
+ border: 2px solid var(--primary-low-mid);
+ border-radius: 5px;
+ align-items: center;
+ display: flex;
+ justify-content: center;
+ position: relative;
+ box-sizing: border-box;
+ background: var(--secondary);
+ flex-shrink: 0;
+ overflow: hidden;
+ transition: border 0.2s ease;
+
+ &::before {
+ content: "";
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ width: 50%;
+ height: 50%;
+ background: var(--tertiary-high);
+ border-radius: 50%;
+ transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
+ opacity: 0;
+ transform: translate(-50%, -50%) scale(0);
+ }
+
+ .d-icon {
+ display: none;
+ width: 75%;
+ height: 75%;
+ }
+ }
+
+ &__control-checkbox-content {
+ flex-direction: column;
+ gap: 0.25rem;
+ }
+
+ &__control-checkbox-description {
+ color: var(--primary-medium);
+
+ &:empty {
+ display: none;
+ }
+ }
+ }
+
+ .form-kit__control-checkbox-label:hover
+ .form-kit__control-checkbox-checkmark {
+ border-color: var(--tertiary-high);
+ }
+
+ .form-kit__control-checkbox:checked + .form-kit__control-checkbox-checkmark {
+ border-color: var(--tertiary-low);
+
+ &::before {
+ opacity: 1;
+ transform: translate(-50%, -50%) scale(3);
+ }
+
+ .d-icon {
+ display: initial;
+ color: var(--secondary);
+ }
+ }
+}
diff --git a/app/assets/stylesheets/common/form-kit/_index.scss b/app/assets/stylesheets/common/form-kit/_index.scss
index c99008e4c90..6af38bb9e0f 100644
--- a/app/assets/stylesheets/common/form-kit/_index.scss
+++ b/app/assets/stylesheets/common/form-kit/_index.scss
@@ -8,6 +8,7 @@
@import "_conditional-display";
@import "_container";
@import "_control-checkbox";
+@import "_control-checkbox-upcoming-changes";
@import "_control-code";
@import "_control-color";
@import "_control-composer";
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 84bbd7529d7..9047643596b 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2747,6 +2747,7 @@ en:
show_preview_for_form_templates: "Enable the preview for form templates feature"
lazy_load_categories_groups: "Lazy load category information only for users of these groups. This improves performance on sites with many categories."
enable_auto_grid_images: "Automatically wraps images in [grid] tags when 3 or more images are uploaded in the composer."
+ enable_new_checkbox_style: "Enable the redesigned checkbox style for FormKit checkboxes."
impersonate_without_logout: "Allow admins to impersonate a user without having to log out of their admin account."
experimental_impersonation_time_limit_minutes: "How long before an impersonation session is automatically ended."
page_loading_indicator: "Configure the loading indicator which appears during page navigations within Discourse. 'Spinner' is a full page indicator. 'Slider' shows a narrow bar at the top of the screen."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index c8ad7b382be..48ac648bf2d 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4243,6 +4243,14 @@ experimental:
status: "beta"
impact: "feature,all_members"
learn_more_url: "https://meta.discourse.org/t/-/394784"
+ enable_new_checkbox_style:
+ default: false
+ client: true
+ hidden: true
+ area: "experimental"
+ upcoming_change:
+ status: "experimental"
+ impact: "feature,all_members"
rename_faq_to_guidelines:
default: false
hidden: true
diff --git a/frontend/discourse/app/form-kit/components/fk/control/checkbox.gjs b/frontend/discourse/app/form-kit/components/fk/control/checkbox.gjs
index ab599c4cd71..143fe00d9ea 100644
--- a/frontend/discourse/app/form-kit/components/fk/control/checkbox.gjs
+++ b/frontend/discourse/app/form-kit/components/fk/control/checkbox.gjs
@@ -1,13 +1,16 @@
import { on } from "@ember/modifier";
import { action } from "@ember/object";
+import { service } from "@ember/service";
import FKBaseControl from "discourse/form-kit/components/fk/control/base";
import FKLabel from "discourse/form-kit/components/fk/label";
import FKRequired from "discourse/form-kit/components/fk/required";
import FKTooltip from "discourse/form-kit/components/fk/tooltip";
+import icon from "discourse/helpers/d-icon";
import { eq, or } from "discourse/truth-helpers";
export default class FKControlCheckbox extends FKBaseControl {
static controlType = "checkbox";
+ @service siteSettings;
@action
handleInput(event) {
@@ -28,6 +31,11 @@ export default class FKControlCheckbox extends FKBaseControl {
...attributes
{{on "change" this.handleInput}}
/>
+ {{#if this.siteSettings.enable_new_checkbox_style}}
+ <span class="form-kit__control-checkbox-checkmark">{{icon
+ "check"
+ }}</span>
+ {{/if}}
<span class="form-kit__control-checkbox-content">
<span class="form-kit__control-checkbox-title">
<span>{{or @title @field.title}}</span>
diff --git a/public/images/upcoming_changes/enable_new_checkbox_style.png b/public/images/upcoming_changes/enable_new_checkbox_style.png
new file mode 100644
index 00000000000..276447dc4e8
Binary files /dev/null and b/public/images/upcoming_changes/enable_new_checkbox_style.png differ