-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FCT-1072 - implement filters
Badge
component (#2936)
* chore(rebase): rebase yarn.lock with main * fix(triggerButton): remove import/render of badge from triggerbutton temporarily so ts likes me again * fix(filters test): you try to do nice things and then you get yelled at by jest and ts, here you go jest plz be happy now that the filters component is displaying the fake label prop * fix(bage styles): badge height 24px * feat(badge): set aria-label only when passed as props, update test * chore(badge): add local-dev tag back to storybook so that we dont publish the filters story on prod, use design tokens in throwaway filters component
- Loading branch information
1 parent
22b962a
commit e7df60b
Showing
8 changed files
with
82 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { screen, render } from '../../../../../test/test-utils'; | ||
import Badge from './badge'; | ||
|
||
/** | ||
* THIS IS A PLACEHOLDER, PLEASE UPDATE IT | ||
*/ | ||
describe('FilterMenu Badge', () => { | ||
const defaultProps = { | ||
label: '+1', | ||
id: 'test-badge', | ||
}; | ||
describe('Filters Badge', () => { | ||
it('should render the badge', async () => { | ||
await render(<Badge />); | ||
await screen.findByText('badge'); | ||
await render(<Badge {...defaultProps} />); | ||
const badge = await screen.findByRole('status'); | ||
expect(badge.textContent).toEqual('+1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,57 @@ | ||
function Badge() { | ||
return <div>badge</div>; | ||
import { css } from '@emotion/react'; | ||
import { designTokens } from '@commercetools-uikit/design-system'; | ||
|
||
export type TBadgeProps = { | ||
/** | ||
* CSS ID for badge, used to specify relationship with parent in parent's `aria-controls` property | ||
* see https://www.w3.org/TR/wai-aria-1.1/#status | ||
*/ | ||
id: string; | ||
/** | ||
* If `true`, indicates that the element is in a disabled state. | ||
*/ | ||
isDisabled?: boolean; | ||
/** | ||
* String to be displayed in badge, generally a count of some kind | ||
*/ | ||
label: string; | ||
|
||
/** | ||
* Optional descriptive explanation of label (e.g. "+4 additional filters applied") | ||
*/ | ||
['aria-label']?: string; | ||
}; | ||
|
||
const badgeStyles = css` | ||
font-size: ${designTokens.fontSize20}; | ||
font-weight: ${designTokens.fontWeight500}; | ||
line-height: ${designTokens.lineHeight20}; | ||
color: ${designTokens.colorSurface}; | ||
background-color: ${designTokens.colorInfo}; | ||
padding: 0 calc(${designTokens.spacing05} + ${designTokens.spacing10}); | ||
border-radius: ${designTokens.borderRadius20}; | ||
display: inline-flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: ${designTokens.spacing40}; | ||
`; | ||
|
||
const disabledBageStyles = css` | ||
background-color: ${designTokens.colorNeutral}; | ||
`; | ||
|
||
function Badge(props: TBadgeProps) { | ||
return ( | ||
<span | ||
aria-label={props['aria-label']} | ||
css={[badgeStyles, props.isDisabled && disabledBageStyles]} | ||
id={props.id} | ||
role="status" | ||
> | ||
{props.label} | ||
</span> | ||
); | ||
} | ||
|
||
export default Badge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3089,7 +3089,7 @@ __metadata: | |
languageName: unknown | ||
linkType: soft | ||
|
||
"@commercetools-uikit/[email protected], @commercetools-uikit/design-system@workspace:design-system": | ||
"@commercetools-uikit/[email protected], @commercetools-uikit/design-system@workspace:^, @commercetools-uikit/design-system@workspace:design-system": | ||
version: 0.0.0-use.local | ||
resolution: "@commercetools-uikit/design-system@workspace:design-system" | ||
dependencies: | ||
|
@@ -3229,7 +3229,9 @@ __metadata: | |
dependencies: | ||
"@babel/runtime": ^7.20.13 | ||
"@babel/runtime-corejs3": ^7.20.13 | ||
"@commercetools-uikit/design-system": "workspace:^" | ||
"@commercetools-uikit/dropdown-menu": "workspace:^" | ||
"@commercetools-uikit/utils": "workspace:^" | ||
"@emotion/react": ^11.10.5 | ||
"@emotion/styled": ^11.10.5 | ||
prop-types: 15.8.1 | ||
|
@@ -4668,7 +4670,7 @@ __metadata: | |
languageName: unknown | ||
linkType: soft | ||
|
||
"@commercetools-uikit/[email protected], @commercetools-uikit/utils@workspace:packages/utils": | ||
"@commercetools-uikit/[email protected], @commercetools-uikit/utils@workspace:^, @commercetools-uikit/utils@workspace:packages/utils": | ||
version: 0.0.0-use.local | ||
resolution: "@commercetools-uikit/utils@workspace:packages/utils" | ||
dependencies: | ||
|