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

Add <TextButton> to Radiance ✨ #75

Merged
merged 4 commits into from
Mar 28, 2019
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
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/linkButton.md → docs/button/linkButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { LinkButton } from 'radiance-ui';
I am Disabled
</LinkButton>
</LinkButton.Container>
</React.Fragment>;
</React.Fragment>
```

#### React Router Link
Expand All @@ -38,7 +38,7 @@ import { Link } from 'react-router';

<LinkButton to="/somepath" as={Link}>
Router Link
</LinkButton>;
</LinkButton>
```

<!-- STORY -->
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions docs/button/textButton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# TextButton

### Usage

```jsx
import { TextButton } from 'radiance-ui';

<TextButton onClick={this.handleClick}>
This text is clickable
</TextButton>

<TextButton disabled>
This is disabled
</TextButton>
```

<!-- STORY -->

### Proptypes


| prop | propType | required | default | description |
| -------- | -------- | -------- | -------- | ------------------------------------------------------- |
| onClick | func | no | () => {} | The callback funciton to call when component is clicked |
| disabled | bool | no | false | When true, `onClick` will not be called |
| children | node | yes | - | Node/text to be rendered inside the button |


### Notes
`TextButton` will render a block of text (or node) that will function as a button. The component renders with padding and should not be used inline within body text, etc. Useful for rendering a chunk of text that can be clicked but can also be disabled if needed.
33 changes: 33 additions & 0 deletions src/shared-components/button/components/textButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import PropTypes from 'prop-types';

import { ButtonContents } from '../../style';
import { BaseTextButton } from './style';

const propTypes = {
disabled: PropTypes.bool,
children: PropTypes.node.isRequired,
onClick: PropTypes.func,
};

const defaultProps = {
disabled: false,
onClick() {},
};

const TextButton = ({
disabled, children, onClick, ...rest
}) => (
<BaseTextButton
disabled={disabled}
onClick={!disabled ? onClick : event => event.preventDefault()}
{...rest}
>
<ButtonContents hasIcon={false}>{children}</ButtonContents>
</BaseTextButton>
);

TextButton.propTypes = propTypes;
TextButton.defaultProps = defaultProps;

export default TextButton;
22 changes: 22 additions & 0 deletions src/shared-components/button/components/textButton/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import styled from '@emotion/styled';

import { COLORS } from '../../../../constants';

/* eslint-disable-next-line import/prefer-default-export */
export const BaseTextButton = styled.button`
border-color: transparent;
background-color: transparent;

color: ${({ disabled }) => `${disabled ? COLORS.textDisabled : COLORS.primary}` };
cursor: ${({ disabled }) => disabled ? 'not-allowed' : 'pointer' };

&:hover {
opacity: 0.8;
background-color: transparent;
}

&:active,
&:focus {
outline: none;
}
`;
1 change: 1 addition & 0 deletions src/shared-components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ class Button extends React.Component {

export LinkButton from './components/linkButton';
export RoundButton from './components/roundButton';
export TextButton from './components/textButton';
export default Button;
2 changes: 1 addition & 1 deletion src/shared-components/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as Accordion } from './accordion';
export { default as Alert } from './alert';
export { default as Banner } from './banner';
export { default as Button, RoundButton, LinkButton } from './button';
export { default as Button, RoundButton, LinkButton, TextButton } from './button';
export { default as Checkbox } from './checkbox';
export { default as Chip } from './chip';
export { default as Container } from './container';
Expand Down
26 changes: 22 additions & 4 deletions stories/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { withKnobs, text, select, boolean } from '@storybook/addon-knobs';
import { action } from '@storybook/addon-actions';
import { css } from '@emotion/core';

import ButtonReadme from 'docs/button.md';
import RoundButtonReadme from 'docs/roundButton.md';
import LinkButtonReadme from 'docs/linkButton.md';
import ButtonReadme from 'docs/button/button.md';
import RoundButtonReadme from 'docs/button/roundButton.md';
import LinkButtonReadme from 'docs/button/linkButton.md';
import TextButtonReadme from 'docs/button/textButton.md';
import { CheckmarkIcon, ArrowLeftIcon, ArrowRightIcon } from 'src/svgs/icons';
import { Button, RoundButton, LinkButton, Typography } from 'src/shared-components';
import { Button, RoundButton, LinkButton, TextButton, Typography } from 'src/shared-components';
import { SPACING } from 'src/constants';

const stories = storiesOf('Buttons', module);
Expand Down Expand Up @@ -191,3 +192,20 @@ stories.add(
</React.Fragment>
))
);

stories.add(
'TextButton',
withDocs(TextButtonReadme, () => (
<React.Fragment>
<Container>
<TextButton onClick={action('Button was clicked')}>
All of this text is clickable
</TextButton>
<br/>
<TextButton disabled>
This text button is disabled
</TextButton>
</Container>
</React.Fragment>
))
);