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

feat: implement size prop on badge component #2014

Merged
merged 3 commits into from
Nov 22, 2020
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
1 change: 1 addition & 0 deletions src/components/Badge/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface BadgeProps extends BaseProps {
label?: ReactNode;
title?: string;
children?: ReactNode;
size?: 'small' | 'medium' | 'large';
variant?:
| 'default'
| 'inverse'
Expand Down
14 changes: 12 additions & 2 deletions src/components/Badge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import Content from './content';
* Badges are labels that hold small amounts of information.
*/
export default function Badge(props) {
const { className, style, label, title, children, variant } = props;
const { className, style, label, title, children, variant, size } = props;

if (children === null && label === null) {
return null;
}

return (
<StyledContainer className={className} style={style} variant={variant} title={title}>
<StyledContainer
className={className}
style={style}
variant={variant}
title={title}
size={size}
>
<Content label={label}>{children}</Content>
</StyledContainer>
);
Expand All @@ -40,6 +46,9 @@ Badge.propTypes = {
'success',
'error',
]),
/** The size of the badge. Valid values are small, and large.
* This value defaults to medium. */
size: PropTypes.oneOf(['small', 'medium', 'large']),
/** A CSS class for the outer element, in addition to the component's base classes. */
className: PropTypes.string,
/** An object with custom style applied to the outer element. */
Expand All @@ -51,6 +60,7 @@ Badge.defaultProps = {
title: undefined,
children: null,
variant: 'default',
size: 'medium',
className: undefined,
style: undefined,
};
14 changes: 14 additions & 0 deletions src/components/Badge/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,17 @@ import { faStar } from '@fortawesome/free-solid-svg-icons';
</Badge>
</div>
```

# Badges of different sizes
##### If you need to resize your badge, you can do so using the `size` prop.

```js
import React from 'react';
import { Badge } from 'react-rainbow-components';

<div className="rainbow-p-vertical_large rainbow-align-content_center rainbow-flex_wrap">
<Badge size="small" variant="inverse" title="the badge title" className="rainbow-m-around_medium" label="Badge Small" />
<Badge size="medium" variant="inverse" title="the badge title" className="rainbow-m-around_medium" label="Badge Medium" />
<Badge size="large" variant="inverse" title="the badge title" className="rainbow-m-around_medium" label="Badge Large" />
</div>
```
18 changes: 16 additions & 2 deletions src/components/Badge/styled/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@ const StyledContainer = attchThemeAttrs(styled.span).attrs(props => {
justify-content: center;
align-content: center;
align-items: center;
font-size: 0.75rem;
line-height: normal;
text-transform: uppercase;
letter-spacing: 0.0625em;
padding: 0.25rem 0.75rem;
border-radius: 12rem;
overflow: hidden;
padding: 0.25rem 0.75rem;
font-size: 0.75rem;

& + & {
margin-left: 0.5rem;
}

${props =>
props.size === 'large' &&
`
padding: 0.65rem 0.9rem;
font-size: 0.9rem;
`};

${props =>
props.size === 'small' &&
`
padding: 0.15rem 0.4rem;
font-size: 0.7rem;
`};

${props =>
props.variant === 'lightest' &&
`
Expand Down