Skip to content

Commit b307903

Browse files
authored
Merge pull request #17 from BeeInventor/develop
feat: add dark mode to dropdown
2 parents e01094b + 3592a27 commit b307903

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

.storybook/preview.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const parameters = {
3030
name: 'light',
3131
value: '#EBEBEB',
3232
},
33+
{
34+
name: 'secondary80',
35+
value: '#656565',
36+
},
3337
],
3438
},
3539
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beeinventor/dasiot-react-component-lib",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"module": "lib/index.js",
55
"types": "lib/index.d.ts",
66
"files": [

src/components/Dropdown/Dropdown.stories.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,25 @@ export default {
3434
argTypes: {
3535
onSelect: { action: 'onSelected' },
3636
disabled: {
37-
control: {
38-
type: 'boolean',
39-
},
37+
control: 'boolean',
38+
defaultValue: false,
4039
},
4140
className: {
42-
control: 'string',
41+
control: 'text',
4342
},
4443
listClassName: {
45-
control: 'string',
44+
control: 'text',
4645
},
4746
itemClassName: {
48-
control: 'string',
47+
control: 'text',
4948
},
5049
selectedId: {
51-
control: 'string',
50+
control: 'text',
51+
},
52+
mode: {
53+
control: 'radio',
54+
options: ['dark', 'light'],
55+
defaultValue: 'light',
5256
},
5357
},
5458
} as Meta;
@@ -91,3 +95,17 @@ WithDialog.args = {
9195
disablePortal: true,
9296
},
9397
};
98+
99+
export const DarkMode: Story<DropDownProps> = Template.bind({});
100+
101+
DarkMode.args = {
102+
mode: 'dark',
103+
list,
104+
selectedId: 'A001',
105+
};
106+
107+
DarkMode.parameters = {
108+
backgrounds: {
109+
default: 'secondary80',
110+
},
111+
};

src/components/Dropdown/Dropdown.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ const Root = styled(Box)(({ theme }) => ({
2929
opacity: 0.3,
3030
pointerEvents: 'none',
3131
},
32+
'&.dark': {
33+
color: 'white',
34+
backgroundColor: 'rgba(0, 0 ,0, 0.2)',
35+
},
3236
}));
3337

34-
const List = styled(Box)(() => ({
38+
const List = styled(Box)(({ theme }) => ({
3539
backgroundColor: '#FFF',
3640
margin: '8px auto',
3741
borderRadius: 4,
3842
boxShadow: '0px 4px 4px rgba(0, 0, 0, 0.1)',
43+
'&.dark': {
44+
color: 'white',
45+
backgroundColor: theme.color.secondary.$100,
46+
},
3947
}));
4048

4149
const Item = styled(Box, { label: 'Dropdown-item' })(({ theme }) => ({
@@ -58,6 +66,7 @@ const Dropdown: React.VFC<DropDownProps> = (props) => {
5866
disabled,
5967
onSelect,
6068
popperProps,
69+
mode = 'light',
6170
...otherProps
6271
} = props;
6372
const selectRef = useRef<HTMLDivElement>(null);
@@ -115,6 +124,10 @@ const Dropdown: React.VFC<DropDownProps> = (props) => {
115124
{
116125
'Dropdown--disabled': disabled,
117126
},
127+
{
128+
dark: mode === 'dark',
129+
light: mode === 'light',
130+
},
118131
)}
119132
onClick={handleOnClickSelect}
120133
{...otherProps}
@@ -131,7 +144,13 @@ const Dropdown: React.VFC<DropDownProps> = (props) => {
131144
{...popperProps}
132145
>
133146
<ClickAwayListener onClickAway={handleOnClickAway}>
134-
<List style={{ width: selectRef.current?.offsetWidth ?? 'auto' }}>
147+
<List
148+
className={classNames({
149+
dark: mode === 'dark',
150+
light: mode === 'light',
151+
})}
152+
style={{ width: selectRef.current?.offsetWidth ?? 'auto' }}
153+
>
135154
{items}
136155
</List>
137156
</ClickAwayListener>

src/components/Dropdown/Dropdown.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ export interface DropDownProps extends Omit<BoxProps, 'onSelect'> {
3636
* Custom popper props
3737
*/
3838
popperProps?: Omit<PopperProps, 'open' | 'anchorEl'>;
39+
mode?: 'dark' | 'light';
3940
}

0 commit comments

Comments
 (0)