-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a "enhanced" theme selector for user settings
- Loading branch information
1 parent
2c2b939
commit dbe5cbd
Showing
4 changed files
with
251 additions
and
41 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
app/routes/users/components/UserSettings/ThemeSelector.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
.label { | ||
font-size: var(--font-size-lg); | ||
margin-bottom: var(--spacing-xs); | ||
} | ||
|
||
.themes { | ||
margin-bottom: var(--spacing-md); | ||
} | ||
|
||
.optionWrapper { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: var(--spacing-xs); | ||
} | ||
|
||
.themeOption { | ||
position: relative; | ||
width: 100px; | ||
height: 100px; | ||
cursor: pointer; | ||
border: 1.5px solid var(--border-gray); | ||
border-radius: var(--border-radius-md); | ||
transition: border-color var(--easing-fast); | ||
overflow: hidden; | ||
} | ||
|
||
.themeOption[data-selected='true'], | ||
.themeOption:hover:not(:disabled), | ||
.themeOption:focus:not(:disabled) { | ||
border-color: var(--color-gray-4); | ||
} | ||
|
||
.previewContent { | ||
height: 100%; | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.previewBackground { | ||
position: absolute; | ||
inset: 0; | ||
z-index: 0; | ||
} | ||
|
||
.previewCard { | ||
position: relative; | ||
margin: var(--spacing-sm); | ||
flex-grow: 1; | ||
border-radius: var(--border-radius-sm); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.previewText { | ||
font-size: var(--font-size-lg); | ||
font-weight: 500; | ||
} | ||
|
||
.auto .previewBackground { | ||
background: linear-gradient( | ||
135deg, | ||
var(--light-background-color) 0%, | ||
var(--light-background-color) 50%, | ||
var(--dark-background-color) 50%, | ||
var(--dark-background-color) 100% | ||
); | ||
} | ||
|
||
.auto .previewCard { | ||
background: linear-gradient( | ||
135deg, | ||
var(--light-card-color) 0%, | ||
var(--light-card-color) 50%, | ||
var(--dark-card-color) 50%, | ||
var(--dark-card-color) 100% | ||
); | ||
} | ||
|
||
.auto .previewText { | ||
background: linear-gradient( | ||
135deg, | ||
var(--light-font-color) 0%, | ||
var(--light-font-color) 50%, | ||
var(--dark-font-color) 50%, | ||
var(--dark-font-color) 100% | ||
); | ||
background-clip: text; | ||
color: transparent; | ||
} | ||
|
||
.light .previewBackground { | ||
background-color: var(--light-background-color); | ||
} | ||
|
||
.light .previewCard { | ||
background-color: var(--light-card-color); | ||
} | ||
|
||
.light .previewText { | ||
color: var(--light-font-color); | ||
} | ||
|
||
.dark .previewBackground { | ||
background-color: var(--dark-background-color); | ||
} | ||
|
||
.dark .previewCard { | ||
background-color: var(--dark-card-color); | ||
} | ||
|
||
.dark .previewText { | ||
color: var(--dark-font-color); | ||
} | ||
|
||
.checkIcon { | ||
position: absolute; | ||
bottom: var(--spacing-xs); | ||
right: var(--spacing-xs); | ||
padding: calc(var(--spacing-xs) / 2); | ||
border-radius: 50%; | ||
opacity: 0; | ||
transition: opacity var(--easing-fast); | ||
} | ||
|
||
.light .checkIcon { | ||
color: var(--dark-font-color); | ||
background: var(--dark-card-color); | ||
} | ||
|
||
.auto .checkIcon, | ||
.dark .checkIcon { | ||
color: var(--light-font-color); | ||
background: var(--light-card-color); | ||
} | ||
|
||
.themeOption[data-selected='true'] .checkIcon { | ||
opacity: 1; | ||
} | ||
|
||
.optionLabel { | ||
font-size: var(--font-size-sm); | ||
} |
85 changes: 85 additions & 0 deletions
85
app/routes/users/components/UserSettings/ThemeSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Flex, Icon } from '@webkom/lego-bricks'; | ||
import cx from 'classnames'; | ||
import { Check, MoonStar, Sun, SunMoon } from 'lucide-react'; | ||
import { useEffect } from 'react'; | ||
import { Field, useForm } from 'react-final-form'; | ||
import { useTheme } from 'app/utils/themeUtils'; | ||
import styles from './ThemeSelector.module.css'; | ||
import type { ReactNode } from 'react'; | ||
|
||
type ThemeOption = { | ||
icon: ReactNode; | ||
label: string; | ||
value: 'dark' | 'light' | 'auto'; | ||
}; | ||
|
||
const themeOptions: ThemeOption[] = [ | ||
{ | ||
icon: <SunMoon />, | ||
label: 'Auto', | ||
value: 'auto', | ||
}, | ||
{ | ||
icon: <Sun />, | ||
label: 'Lyst', | ||
value: 'light', | ||
}, | ||
{ | ||
icon: <MoonStar />, | ||
label: 'Mørkt', | ||
value: 'dark', | ||
}, | ||
]; | ||
|
||
const ThemeSelector = () => { | ||
const form = useForm(); | ||
const theme = useTheme(); | ||
|
||
useEffect(() => { | ||
form.change('selectedTheme', theme); | ||
}, [form, theme]); | ||
|
||
return ( | ||
<div> | ||
<label className={styles.label}>Fargetema</label> | ||
<Flex wrap gap="var(--spacing-md)" className={styles.themes}> | ||
{themeOptions.map((option) => ( | ||
<Field | ||
name="selectedTheme" | ||
type="radio" | ||
value={option.value} | ||
key={option.value} | ||
> | ||
{({ input }) => ( | ||
<div className={styles.optionWrapper}> | ||
<div | ||
className={cx(styles.themeOption, styles[option.value])} | ||
data-selected={input.checked} | ||
onClick={() => input.onChange(option.value)} | ||
> | ||
<div className={styles.previewBackground} /> | ||
<div className={styles.previewContent}> | ||
<div className={styles.previewCard}> | ||
<div className={styles.previewText}>Aa</div> | ||
</div> | ||
</div> | ||
<Icon | ||
iconNode={<Check />} | ||
size={16} | ||
className={styles.checkIcon} | ||
/> | ||
</div> | ||
<Flex alignItems="center" gap="var(--spacing-xs)"> | ||
<Icon iconNode={option.icon} size={16} /> | ||
<div className={styles.optionLabel}>{option.label}</div> | ||
</Flex> | ||
</div> | ||
)} | ||
</Field> | ||
))} | ||
</Flex> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ThemeSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters