Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ new(react-dropdown): Allow options to change font color. #99

Merged
merged 3 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions packages/react-dropdown/docs/react-dropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,42 @@ import React from 'react';
import { Dropdown } from '../lib/react-dropdown';

export default {
title: 'Components/Dropdown'
title: 'Components/Dropdown',
argTypes: {
position: {
type: {
name: 'string',
required: false
},
description: 'This property will determine where the dropdown menu will be placed.',
defaultValue: 'left',
control: {
type: 'select',
options: [
'left',
'center',
'right'
]
},
table: {
type: {
summary: 'options',
detail: '"left", "center", "right"'
},
defaultValue: {
summary: 'left'
}
},
},
children: {
data: {
type: 'array'
},
control: {
type: null
}
}
}
}

const Template = ({ children, ...args }) => {
Expand All @@ -27,22 +62,11 @@ primary.args = {
name: 'Option 2'
},
{
name: 'Option 3'
name: 'Option 3',
color: 'red'
},
]
};
primary.argTypes = {
position: {
control: {
type: 'select',
options: [
'left',
'center',
'right'
]
}
}
};

export const secondary = Template.bind({});
secondary.storyName = 'Option Icon';
Expand All @@ -63,9 +87,6 @@ secondary.args = {
},
]
};
secondary.argTypes = {
...primary.argTypes
};

export const tertiary = Template.bind({});
tertiary.storyName = 'Option Tag';
Expand All @@ -85,7 +106,4 @@ tertiary.args = {
tag: 'Coming Soon'
},
]
};
tertiary.argTypes = {
...primary.argTypes
};
53 changes: 51 additions & 2 deletions packages/react-dropdown/lib/react-dropdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
import React, { Component, Children, Fragment } from 'react';
import { ButtonIcon } from '@wpmudev/react-button-icon';
import styled from 'styled-components';

const Link = styled.a`
.sui-wrap && {
${props => ('blue' === props.color ? 'color: #17A8E3 !important;' : '')}
${props => ('green' === props.color ? 'color: #1ABC9C !important;' : '')}
${props => ('yellow' === props.color ? 'color: #FECF2F !important;' : '')}
${props => ('red' === props.color ? 'color: #FF6D6D !important;' : '')}
${props => ('purple' === props.color ? 'color: #8D00B1 !important;' : '')}

&:hover,
&:focus {
${props => ('blue' === props.color ? 'background-color: #E1F6FF !important;' : '')}
${props => ('green' === props.color ? 'background-color: #D1F1EA !important;' : '')}
${props => ('yellow' === props.color ? 'background-color: #FFF5D5 !important;' : '')}
${props => ('red' === props.color ? 'background-color: #FFE5E9 !important;' : '')}
${props => ('purple' === props.color ? 'background-color: #F9E1FF !important;' : '')}
}
}
`;

const Button = styled.button`
.sui-wrap && {
${props => ('blue' === props.color ? 'color: #17A8E3 !important;' : '')}
${props => ('green' === props.color ? 'color: #1ABC9C !important;' : '')}
${props => ('yellow' === props.color ? 'color: #FECF2F !important;' : '')}
${props => ('red' === props.color ? 'color: #FF6D6D !important;' : '')}
${props => ('purple' === props.color ? 'color: #8D00B1 !important;' : '')}

&:hover,
&:focus {
${props => ('blue' === props.color ? 'background-color: #E1F6FF !important;' : '')}
${props => ('green' === props.color ? 'background-color: #D1F1EA !important;' : '')}
${props => ('yellow' === props.color ? 'background-color: #FFF5D5 !important;' : '')}
${props => ('red' === props.color ? 'background-color: #FFE5E9 !important;' : '')}
${props => ('purple' === props.color ? 'background-color: #F9E1FF !important;' : '')}
}
}
`;

export class Dropdown extends Component {
constructor( props ) {
Expand Down Expand Up @@ -65,10 +104,20 @@ export class Dropdown extends Component {
const label = <Fragment>{ icon }{ option.props.name }{ tag }</Fragment>;

if ( option.props.href ) {
return <li><a href={ option.props.href } {...option.props}>{ label }</a></li>;
return <li>
<Link
href={ option.props.href }
{ ...option.props }>
{ label }
</Link>
</li>;
}

return <li><button {...option.props}>{ label }</button></li>;
return <li>
<Button { ...option.props }>
{ label }
</Button>
</li>;
});

let clazz = !open
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dropdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
},
"homepage": "https://github.com/wpmudev/shared-ui-react#readme",
"dependencies": {
"@wpmudev/react-button-icon": "^1.0.1"
"@wpmudev/react-button-icon": "^1.0.1",
"styled-components": "^5.2.3"
},
"devDependencies": {
"@wpmudev/react-builder": "^0.0.0",
Expand Down