-
Notifications
You must be signed in to change notification settings - Fork 0
Style updates #1
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| node_modules | ||
| .env |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import React, { Fragment } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| import './styles.css'; | ||
| import classnames from 'classnames'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move up |
||
|
|
||
| const CountBadge = ({ | ||
| children, | ||
| hideCount, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| isAttached, | ||
| fillColor, | ||
| strokeColor, | ||
| size, | ||
| }) => { | ||
| const count = | ||
| children > 99 ? ( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Magic numbers. Replace with |
||
| <Fragment> | ||
| 99<sup>+</sup> | ||
| </Fragment> | ||
| ) : ( | ||
| children | ||
| ); | ||
| return ( | ||
| <div | ||
| className={classnames([ | ||
| 'CountBadge', | ||
| { | ||
| 'CountBadge__is-attached': isAttached, | ||
| }, | ||
| ])} | ||
| style={{ | ||
| color: strokeColor, | ||
| backgroundColor: fillColor, | ||
| fontSize: size / 2, | ||
| height: size, | ||
| width: size, | ||
| }} | ||
| title={children} | ||
| > | ||
| {hideCount ? null : count} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| CountBadge.propTypes = { | ||
| hideCount: PropTypes.bool, | ||
| children: PropTypes.string.isRequired, | ||
| strokeColor: PropTypes.string, | ||
| fillColor: PropTypes.string, | ||
| size: PropTypes.number, | ||
| }; | ||
|
|
||
| CountBadge.defaultProps = { | ||
| hideCount: false, | ||
| isAttached: false, | ||
| strokeColor: '#ffffff', | ||
| fillColor: '#d01c1c', | ||
| size: 24, | ||
| }; | ||
|
|
||
| export default CountBadge; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| .CountBadge { | ||
| align-items: center; | ||
| border-radius: 100%; | ||
| display: flex; | ||
| font-weight: bold; | ||
| justify-content: center; | ||
| margin: 1px; | ||
| position: relative; | ||
| } | ||
|
|
||
| .CountBadge__is-attached { | ||
| position: absolute; | ||
| top: 0; | ||
| right: 0; | ||
| transform: translate(55%, -55%); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel that this relies on the outer element having a position relative which doesn't encapsulate this component - it creates a dependency on the outside world rather than being atomic. Options:
Obviously option 2 will have a impact on performance, so should consider looking at stifling re-renders. For now, let's remove this feature and open an issue to investigate and add. |
||
| } | ||
|
|
||
| .CountBadge::after { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we leave some more comments in the CSS as to what the intent of the pseudo class is. |
||
| border-radius: 100%; | ||
| border: 0.18em solid; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we need an explicit |
||
| bottom: -1px; /* -1px on position to tackle background colour fuzzing */ | ||
| content: ''; | ||
| left: -1px; | ||
| position: absolute; | ||
| right: -1px; | ||
| top: -1px; | ||
| } | ||
|
|
||
| sup { | ||
| transform: translateY(-20%); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import React from 'react'; | ||
| import { CountBadge, Clickable } from '../src'; | ||
|
|
||
| export default { | ||
| title: 'CountBadge', | ||
| }; | ||
|
|
||
| export const twelve = () => <CountBadge>12</CountBadge>; | ||
| export const four = () => <CountBadge fillColor="#797979">4</CountBadge>; | ||
| export const one = () => ( | ||
| <CountBadge strokeColor="#333333" fillColor="#c78ae3"> | ||
| 1 | ||
| </CountBadge> | ||
| ); | ||
| export const ninetyNine = () => <CountBadge fillColor="#006dcc">99</CountBadge>; | ||
| export const twoHundred = () => <CountBadge>200</CountBadge>; | ||
| export const small = () => <CountBadge size={16}>2</CountBadge>; | ||
| export const smallNoCount = () => ( | ||
| <CountBadge hideCount size={12}> | ||
| 2 | ||
| </CountBadge> | ||
| ); | ||
| export const large = () => ( | ||
| <CountBadge fillColor="#e7912f" strokeColor="#e7542f" size={100}> | ||
| 50 | ||
| </CountBadge> | ||
| ); | ||
| export const extraLarge = () => <CountBadge size={400}>88</CountBadge>; | ||
|
|
||
| export const attached = () => ( | ||
| <span style={{ position: 'relative' }}> | ||
| <Clickable | ||
| onClick={() => { | ||
| return; | ||
| }} | ||
| > | ||
| Count | ||
| </Clickable> | ||
| <CountBadge size={24} isAttached>2</CountBadge> | ||
| </span> | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create an issue for styled components