From 3711b60c1e5ef4d04a13c02e2342b1a6b0807269 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Thu, 5 Sep 2024 17:30:33 +0530 Subject: [PATCH] Add the UI toggle for changing theme (#4840) Co-authored-by: zackdotcat Co-authored-by: zack <6351754+zackkrida@users.noreply.github.com> --- frontend/feat/feature-flags.json | 9 --- frontend/src/assets/svg/raw/moon.svg | 8 ++ frontend/src/assets/svg/raw/sun.svg | 13 ++++ frontend/src/assets/svg/sprite/icons.svg | 2 + frontend/src/components/VFooter/VFooter.vue | 31 ++++++-- .../components/VSelectField/VSelectField.vue | 11 ++- .../components/VThemeSelect/VThemeSelect.vue | 76 +++++++++++++++++++ frontend/src/composables/use-dark-mode.ts | 46 +++++++++-- frontend/src/locales/scripts/en.json5 | 8 ++ .../specs/composables/use-dark-mode.spec.ts | 47 ++++++++---- 10 files changed, 213 insertions(+), 38 deletions(-) create mode 100644 frontend/src/assets/svg/raw/moon.svg create mode 100644 frontend/src/assets/svg/raw/sun.svg create mode 100644 frontend/src/components/VThemeSelect/VThemeSelect.vue diff --git a/frontend/feat/feature-flags.json b/frontend/feat/feature-flags.json index 5d8c5fe4b48..74c70dd3e75 100644 --- a/frontend/feat/feature-flags.json +++ b/frontend/feat/feature-flags.json @@ -31,15 +31,6 @@ "supportsQuery": false, "storage": "session" }, - "force_dark_mode": { - "status": { - "staging": "switchable", - "production": "disabled" - }, - "defaultState": "off", - "description": "Force the site to render in dark mode.", - "storage": "session" - }, "dark_mode_ui_toggle": { "status": { "staging": "switchable", diff --git a/frontend/src/assets/svg/raw/moon.svg b/frontend/src/assets/svg/raw/moon.svg new file mode 100644 index 00000000000..0d13e051cac --- /dev/null +++ b/frontend/src/assets/svg/raw/moon.svg @@ -0,0 +1,8 @@ + + + + + diff --git a/frontend/src/assets/svg/raw/sun.svg b/frontend/src/assets/svg/raw/sun.svg new file mode 100644 index 00000000000..00f4ae1d09d --- /dev/null +++ b/frontend/src/assets/svg/raw/sun.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/frontend/src/assets/svg/sprite/icons.svg b/frontend/src/assets/svg/sprite/icons.svg index 54d9127acc8..615db5de8ae 100644 --- a/frontend/src/assets/svg/sprite/icons.svg +++ b/frontend/src/assets/svg/sprite/icons.svg @@ -35,4 +35,6 @@ + + diff --git a/frontend/src/components/VFooter/VFooter.vue b/frontend/src/components/VFooter/VFooter.vue index 87880908dcb..330422e22fe 100644 --- a/frontend/src/components/VFooter/VFooter.vue +++ b/frontend/src/components/VFooter/VFooter.vue @@ -11,11 +11,13 @@ import useResizeObserver from "~/composables/use-resize-observer" import { SCREEN_SIZES } from "~/constants/screens" import { useUiStore } from "~/stores/ui" +import { useFeatureFlagStore } from "~/stores/feature-flag" import type { SelectFieldProps } from "~/components/VSelectField/VSelectField.vue" import VLink from "~/components/VLink.vue" import VBrand from "~/components/VBrand/VBrand.vue" import VLanguageSelect from "~/components/VLanguageSelect/VLanguageSelect.vue" +import VThemeSelect from "~/components/VThemeSelect/VThemeSelect.vue" import VPageLinks from "~/components/VHeader/VPageLinks.vue" import VWordPressLink from "~/components/VHeader/VWordPressLink.vue" @@ -42,6 +44,11 @@ const { all: allPages } = usePages() const isContentMode = computed(() => props.mode === "content") +const featureFlagStore = useFeatureFlagStore() +const showThemeSwitcher = computed(() => + featureFlagStore.isOn("dark_mode_ui_toggle") +) + /** JS-based responsiveness */ const footerEl = ref(null) const initialWidth = SCREEN_SIZES[uiStore.breakpoint] @@ -90,11 +97,25 @@ const linkColumnHeight = computed(() => ({
- - + +
diff --git a/frontend/src/components/VSelectField/VSelectField.vue b/frontend/src/components/VSelectField/VSelectField.vue index dd89bcb7ec5..390895c72ab 100644 --- a/frontend/src/components/VSelectField/VSelectField.vue +++ b/frontend/src/components/VSelectField/VSelectField.vue @@ -33,10 +33,12 @@ const props = withDefaults( fieldId: string labelText: string choices: Choice[] + showSelected?: boolean }>(), { modelValue: "", blankText: "", + showSelected: true, } ) @@ -70,7 +72,7 @@ const splitAttrs = computed(() => {