-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-ui): Add IconButton Molecule (#900)
* Add IconButton molecule component * Use IconButton on Carousel * Fix stories and doc * Fix default story and remove children from props * Use css hover instead of tailwind hover * Export IconButton * Trigger CI * Change story css * Change Preview to Default * Fix css * Add css selectors on docs
- Loading branch information
1 parent
6d76cec
commit 0114409
Showing
10 changed files
with
138 additions
and
12 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
27 changes: 27 additions & 0 deletions
27
packages/store-ui/src/molecules/IconButton/IconButton.test.tsx
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
|
||
import IconButton from './IconButton' | ||
|
||
describe('IconButton', () => { | ||
const testId = 'store-icon-button' | ||
|
||
it('data-store-icon-button is present', () => { | ||
const { getByTestId } = render( | ||
<IconButton testId={testId} icon={<div>foo</div>} /> | ||
) | ||
|
||
const iconButton = getByTestId(testId) | ||
|
||
expect(iconButton).toBeInTheDocument() | ||
expect(iconButton).toHaveAttribute('data-store-icon-button') | ||
}) | ||
|
||
it('icon is present', () => { | ||
const { getByTestId } = render( | ||
<IconButton testId={testId} icon={<div data-testid="icon">foo</div>} /> | ||
) | ||
|
||
expect(getByTestId('icon')).toBeInTheDocument() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { ReactNode } from 'react' | ||
import React, { forwardRef } from 'react' | ||
|
||
import Button from '../../atoms/Button' | ||
import type { ButtonProps } from '../../atoms/Button' | ||
import Icon from '../../atoms/Icon' | ||
|
||
export interface Props extends Omit<ButtonProps, 'children'> { | ||
/** | ||
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest). | ||
*/ | ||
testId?: string | ||
/** | ||
* A React component that will be rendered as an icon. | ||
*/ | ||
icon: ReactNode | ||
} | ||
|
||
const IconButton = forwardRef<HTMLButtonElement, Props>(function IconButton( | ||
{ icon, testId = 'store-icon-button', ...buttonProps }, | ||
ref | ||
) { | ||
return ( | ||
<Button ref={ref} data-store-icon-button testId={testId} {...buttonProps}> | ||
<Icon component={icon} /> | ||
</Button> | ||
) | ||
}) | ||
|
||
export default IconButton |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './IconButton' | ||
export type { Props as IconButtonProps } from './IconButton' |
25 changes: 25 additions & 0 deletions
25
packages/store-ui/src/molecules/IconButton/stories/IconButton.mdx
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs' | ||
import IconButton from '../IconButton' | ||
|
||
# Default | ||
|
||
<Canvas> | ||
<Story id="molecules-iconbutton--default" /> | ||
</Canvas> | ||
|
||
# Custom Style | ||
|
||
<Canvas> | ||
<Story id="molecules-iconbutton--custom-style" /> | ||
</Canvas> | ||
|
||
# Props | ||
|
||
<ArgsTable of={IconButton} /> | ||
|
||
# CSS Selectors | ||
```css | ||
[data-store-icon-button] {} | ||
``` | ||
|
||
This component inherits [Button](?path=/docs/atoms-button--button) component css selectors. |
30 changes: 30 additions & 0 deletions
30
packages/store-ui/src/molecules/IconButton/stories/IconButton.stories.tsx
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Story, Meta } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import type { Props as IconButtonProps } from '../IconButton' | ||
import Component from '../IconButton' | ||
import ShoppingCartIcon from '../../../atoms/Icon/stories/assets/ShoppingCart' | ||
import mdx from './IconButton.mdx' | ||
|
||
const IconButtonTemplate: Story<IconButtonProps> = (props) => ( | ||
<Component {...props} icon={<ShoppingCartIcon />} /> | ||
) | ||
|
||
export const Default = IconButtonTemplate.bind({}) | ||
|
||
const IconButtonCustomTemplate: Story<IconButtonProps> = (props) => { | ||
return ( | ||
<Component {...props} className="iconButton" icon={<ShoppingCartIcon />} /> | ||
) | ||
} | ||
|
||
export const CustomStyle = IconButtonCustomTemplate.bind({}) | ||
|
||
export default { | ||
title: 'Molecules/IconButton', | ||
parameters: { | ||
docs: { | ||
page: mdx, | ||
}, | ||
}, | ||
} as Meta |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[data-store-icon-button] { | ||
@apply inline-flex; | ||
} | ||
|
||
.iconButton { | ||
@apply text-black inline-flex bg-transparent cursor-pointer rounded-full p-2 transition-colors duration-150 ease-in; | ||
} | ||
|
||
.iconButton:hover { | ||
@apply bg-gray-400 bg-opacity-40; | ||
} |
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,2 +1,3 @@ | ||
@import "./bullets.css"; | ||
@import "./search-input.css"; | ||
@import "./icon-button.css" |