-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flat-components): add appearance picker component (#1373)
* feat(flat-components): add theme picker component * feat(flat-components): add appearance picker component
- Loading branch information
Showing
13 changed files
with
183 additions
and
11 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
packages/flat-components/src/components/SettingPage/AppearancePicker/ThemePicker.stories.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,22 @@ | ||
import React from "react"; | ||
import { Meta, Story } from "@storybook/react"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
import { AppearancePicker, AppearancePickerProps } from "."; | ||
|
||
const storyMeta: Meta = { | ||
title: "SettingPage/AppearancePicker", | ||
component: AppearancePicker, | ||
}; | ||
|
||
export default storyMeta; | ||
|
||
export const Overview: Story<AppearancePickerProps> = args => ( | ||
<Router> | ||
<div className="vh-75 mw8-ns"> | ||
<AppearancePicker {...args} /> | ||
</div> | ||
</Router> | ||
); | ||
Overview.args = { | ||
defaultValue: "light", | ||
}; |
1 change: 1 addition & 0 deletions
1
...ages/flat-components/src/components/SettingPage/AppearancePicker/icons/auto.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...ages/flat-components/src/components/SettingPage/AppearancePicker/icons/dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...ges/flat-components/src/components/SettingPage/AppearancePicker/icons/light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
packages/flat-components/src/components/SettingPage/AppearancePicker/index.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,45 @@ | ||
import lightSVG from "./icons/light.svg"; | ||
import darkSVG from "./icons/dark.svg"; | ||
import autoSVG from "./icons/auto.svg"; | ||
import "./style.less"; | ||
|
||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Radio, RadioChangeEvent } from "antd"; | ||
import { FlatPrefersColorScheme } from "../../FlatThemeProvider"; | ||
|
||
export interface AppearancePickerProps { | ||
defaultValue: FlatPrefersColorScheme; | ||
changeAppearance: (event: RadioChangeEvent) => void; | ||
} | ||
|
||
export const AppearancePicker: React.FC<AppearancePickerProps> = ({ | ||
defaultValue, | ||
changeAppearance, | ||
}) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<div className="appearance-picker-container"> | ||
<Radio.Group defaultValue={defaultValue} onChange={changeAppearance}> | ||
<Radio value={"light"}> | ||
<div className="appearance-picker-option"> | ||
<img src={lightSVG} /> | ||
<span>{t("flat-appearance-light")}</span> | ||
</div> | ||
</Radio> | ||
<Radio value={"dark"}> | ||
<div className="appearance-picker-option"> | ||
<img src={darkSVG} /> | ||
<span>{t("flat-appearance-dark")}</span> | ||
</div> | ||
</Radio> | ||
<Radio value={"auto"}> | ||
<div className="appearance-picker-option"> | ||
<img src={autoSVG} /> | ||
<span>{t("flat-appearance-auto")}</span> | ||
</div> | ||
</Radio> | ||
</Radio.Group> | ||
</div> | ||
); | ||
}; |
49 changes: 49 additions & 0 deletions
49
packages/flat-components/src/components/SettingPage/AppearancePicker/style.less
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,49 @@ | ||
.appearance-picker-container { | ||
> .ant-radio-group { | ||
> .ant-radio-wrapper { | ||
border-radius: 4px; | ||
padding: 4px; | ||
|
||
> span { | ||
padding: 0; | ||
} | ||
|
||
.ant-radio { | ||
margin-top: 9px; | ||
} | ||
|
||
&::after { | ||
content: ""; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 75%; | ||
position: absolute; | ||
border-radius: 4px; | ||
transition: border-color 0.4s; | ||
} | ||
|
||
&.ant-radio-wrapper-checked, | ||
&:hover, | ||
&:active { | ||
&::after { | ||
border: 2px solid var(--primary); | ||
} | ||
} | ||
} | ||
|
||
.ant-radio { | ||
display: none; | ||
} | ||
} | ||
} | ||
|
||
.appearance-picker-option { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
> span { | ||
padding-top: 8px; | ||
} | ||
} |
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
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
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