Skip to content

Commit

Permalink
feat(button): add a circle shape (uber#3716)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandgraham authored Sep 1, 2020
1 parent 061d5bc commit ce1151e
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 6 deletions.
2 changes: 1 addition & 1 deletion documentation-site/examples/button/shapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default () => (
</Button>
</p>
<p>
<Button shape={SHAPE.round}>
<Button shape={SHAPE.circle}>
<Upload />
</Button>
</p>
Expand Down
2 changes: 1 addition & 1 deletion documentation-site/examples/button/shapes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default () => (
</Button>
</p>
<p>
<Button shape={SHAPE.round}>
<Button shape={SHAPE.circle}>
<Upload />
</Button>
</p>
Expand Down
81 changes: 81 additions & 0 deletions src/button/__tests__/button-circle.scenario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright (c) 2018-2020 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow

import * as React from 'react';
import {useStyletron} from '../../index.js';
import {Button, SHAPE, SIZE, KIND} from '../index.js';
import Upload from '../../icon/upload.js';

export default function Scenario() {
const [css] = useStyletron();
return (
<React.Fragment>
<div>
<Button
key={`circle-kind-primary`}
shape={SHAPE.circle}
kind={KIND.primary}
>
GM
</Button>
<span className={css({display: 'inline-block', width: '10px'})} />
<Button
key={`circle-kind-secondary`}
shape={SHAPE.circle}
kind={KIND.secondary}
>
GM
</Button>
<span className={css({display: 'inline-block', width: '10px'})} />
<Button
key={`circle-kind-tertiary`}
shape={SHAPE.circle}
kind={KIND.tertiary}
>
GM
</Button>
</div>
<br />
<div>
<Button key={`circle-size-mini`} shape={SHAPE.circle} size={SIZE.mini}>
GM
</Button>
<span className={css({display: 'inline-block', width: '10px'})} />
<Button
key={`circle-size-compact`}
shape={SHAPE.circle}
size={SIZE.compact}
>
GM
</Button>
<span className={css({display: 'inline-block', width: '10px'})} />
<Button
key={`circle-size-default`}
shape={SHAPE.circle}
size={SIZE.default}
>
GM
</Button>
<span className={css({display: 'inline-block', width: '10px'})} />
<Button
key={`circle-size-large`}
shape={SHAPE.circle}
size={SIZE.large}
>
GM
</Button>
</div>
<br />
<div>
<Button shape={SHAPE.circle}>
<Upload size={24} />
</Button>
</div>
</React.Fragment>
);
}
1 change: 1 addition & 0 deletions src/button/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const SHAPE = {
default: 'default',
pill: 'pill',
round: 'round',
circle: 'circle',
square: 'square',
};

Expand Down
1 change: 1 addition & 0 deletions src/button/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface SHAPE {
default: 'default';
pill: 'pill';
round: 'round';
circle: 'circle';
square: 'square';
}

Expand Down
53 changes: 49 additions & 4 deletions src/button/styled-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ export const BaseButton = styled<SharedStylePropsT>(
borderRightStyle: 'none',
borderBottomStyle: 'none',
outline:
$isFocusVisible && $shape !== SHAPE.round && $shape !== SHAPE.pill
$isFocusVisible &&
$shape !== SHAPE.circle &&
$shape !== SHAPE.round &&
$shape !== SHAPE.pill
? `3px solid ${$theme.colors.accent}`
: 'none',
outlineOffset: '-3px',
boxShadow:
$isFocusVisible && ($shape === SHAPE.round || $shape === SHAPE.pill)
$isFocusVisible &&
($shape === SHAPE.circle ||
$shape === SHAPE.round ||
$shape === SHAPE.pill)
? `0 0 0 3px ${$theme.colors.accent}`
: 'none',
textDecoration: 'none',
Expand All @@ -63,6 +69,7 @@ export const BaseButton = styled<SharedStylePropsT>(
...getPaddingStyles({$theme, $size, $shape}),
// Kind style override
...getKindStyles({$theme, $kind, $isLoading, $isSelected, $disabled}),
...getShapeStyles({$theme, $shape, $size}),
}),
);

Expand Down Expand Up @@ -205,7 +212,7 @@ function getBorderRadiiStyles({$theme, $size, $shape}) {
} else {
value = '38px';
}
} else if ($shape === SHAPE.round) {
} else if ($shape === SHAPE.circle || $shape === SHAPE.round) {
value = '50%';
}

Expand All @@ -231,7 +238,10 @@ function getFontStyles({$theme, $size}) {
}

function getPaddingStyles({$theme, $size, $shape}) {
const iconShape = $shape === SHAPE.square || $shape === SHAPE.round;
const iconShape =
$shape === SHAPE.square ||
$shape === SHAPE.circle ||
$shape === SHAPE.round;
switch ($size) {
case SIZE.mini:
return {
Expand Down Expand Up @@ -384,3 +394,38 @@ function getKindStyles({
return Object.freeze({});
}
}

function getShapeStyles({$theme, $shape, $size}) {
if ($shape === SHAPE.circle || $shape === SHAPE.square) {
let height, width;
switch ($size) {
case SIZE.mini:
height = '28px';
width = '28px';
break;
case SIZE.compact:
height = '36px';
width = '36px';
break;
case SIZE.large:
height = '56px';
width = '56px';
break;
case SIZE.default:
default:
height = '48px';
width = '48px';
break;
}
return {
height,
width,
paddingTop: 0,
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0,
};
} else {
return {};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vrt/__image_snapshots__/table-grid-jobs__dark-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vrt/__image_snapshots__/table-grid-jobs__desktop-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vrt/__image_snapshots__/table-grid-jobs__mobile-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ce1151e

Please sign in to comment.