-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuselage):
FramedIcon
new component
- Loading branch information
1 parent
5b14962
commit 04b12e6
Showing
7 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/fuselage/src/components/FramedIcon/FramedIcon.spec.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,31 @@ | ||
import { composeStories } from '@storybook/testing-react'; | ||
import { render } from '@testing-library/react'; | ||
import { axe } from 'jest-axe'; | ||
import React from 'react'; | ||
|
||
import * as stories from './FramedIcon.stories'; | ||
|
||
const testCases = Object.values(composeStories(stories)).map((Story) => [ | ||
Story.storyName || 'Story', | ||
Story, | ||
]); | ||
|
||
describe('[FramedIcon rendering]', () => { | ||
test.each(testCases)( | ||
`renders %s without crashing`, | ||
async (_storyname, Story) => { | ||
const tree = render(<Story />); | ||
expect(tree.baseElement).toMatchSnapshot(); | ||
} | ||
); | ||
|
||
test.each(testCases)( | ||
'%s should have no a11y violations', | ||
async (_storyname, Story) => { | ||
const { container } = render(<Story />); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
} | ||
); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/fuselage/src/components/FramedIcon/FramedIcon.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,35 @@ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { FramedIcon } from './FramedIcon'; | ||
|
||
export default { | ||
title: 'Data Display/FramedIcon', | ||
component: FramedIcon, | ||
} as ComponentMeta<typeof FramedIcon>; | ||
|
||
const Template: ComponentStory<typeof FramedIcon> = (args) => ( | ||
<FramedIcon {...args} icon='rocket' /> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
|
||
export const Info = Template.bind({}); | ||
Info.args = { | ||
info: true, | ||
}; | ||
|
||
export const Success = Template.bind({}); | ||
Success.args = { | ||
success: true, | ||
}; | ||
|
||
export const Warning = Template.bind({}); | ||
Warning.args = { | ||
warning: true, | ||
}; | ||
|
||
export const Danger = Template.bind({}); | ||
Danger.args = { | ||
danger: true, | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/fuselage/src/components/FramedIcon/FramedIcon.styles.scss
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,33 @@ | ||
@use '../../styles/colors.scss'; | ||
@use '../../styles/typography.scss'; | ||
@use '../../styles/lengths.scss'; | ||
|
||
.rcx-framed-icon { | ||
@include typography.use-font-scale(p2m); | ||
|
||
padding: lengths.padding(4); | ||
|
||
color: colors.font(secondary-info); | ||
border-radius: lengths.border-radius(medium); | ||
background-color: colors.surface(tint); | ||
|
||
&--info { | ||
color: colors.status-font(on-info); | ||
background-color: colors.status-background(info); | ||
} | ||
|
||
&--success { | ||
color: colors.status-font(on-success); | ||
background-color: colors.status-background(success); | ||
} | ||
|
||
&--warning { | ||
color: colors.status-font(on-warning); | ||
background-color: colors.status-background(warning); | ||
} | ||
|
||
&--danger { | ||
color: colors.status-font(on-danger); | ||
background-color: colors.status-background(danger); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/fuselage/src/components/FramedIcon/FramedIcon.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,35 @@ | ||
import type { Keys } from '@rocket.chat/icons'; | ||
import React from 'react'; | ||
|
||
import { Icon } from '../Icon'; | ||
|
||
type FramedIconProps = { | ||
info?: boolean; | ||
success?: boolean; | ||
warning?: boolean; | ||
danger?: boolean; | ||
neutral?: boolean; | ||
icon: Keys; | ||
}; | ||
|
||
export const FramedIcon = ({ | ||
info, | ||
success, | ||
warning, | ||
danger, | ||
neutral, | ||
icon, | ||
}: FramedIconProps) => ( | ||
<Icon | ||
rcx-framed-icon | ||
rcx-framed-icon--info={info} | ||
rcx-framed-icon--success={success} | ||
rcx-framed-icon--warning={warning} | ||
rcx-framed-icon--danger={danger} | ||
rcx-framed-icon--neutral={ | ||
neutral || (!info && !success && !warning && !danger) | ||
} | ||
name={icon} | ||
size={20} | ||
/> | ||
); |
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 @@ | ||
export * from './FramedIcon'; |
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