Skip to content

Commit e83a302

Browse files
laraharrowLuke Bowerman
andauthored
Status component and add icon Error (#985)
* first commit * create new component Status * create new component Status and add icon Error * updating for review * Fix-up forwardRef * ready for review * ready for review * ready for review * Clean-up on top of new theme shape * Changelog update * Typo in doc Co-authored-by: Luke Bowerman <[email protected]>
1 parent c9a4902 commit e83a302

File tree

12 files changed

+525
-6
lines changed

12 files changed

+525
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `Status` component
1213
- `Tree`, `TreeItem` components
1314
- Includes docs and test suite
1415
- `ActionListItem` accepts `actionsButtonLabel` prop to help with testing
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import 'jest-styled-components'
28+
import React from 'react'
29+
import { assertSnapshot } from '@looker/components-test-utils'
30+
import { Status } from './Status'
31+
32+
test('critical Status', () => {
33+
assertSnapshot(<Status intent="critical" />)
34+
})
35+
36+
test('inform Status', () => {
37+
assertSnapshot(<Status intent="inform" />)
38+
})
39+
40+
test('neutral status', () => {
41+
assertSnapshot(<Status intent="neutral" />)
42+
})
43+
44+
test('positive Status', () => {
45+
assertSnapshot(<Status intent="positive" />)
46+
})
47+
48+
test('warning Status', () => {
49+
assertSnapshot(<Status intent="warning" />)
50+
})
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import { CompatibleHTMLProps, TypographyProps } from '@looker/design-tokens'
28+
import React, { forwardRef, Ref } from 'react'
29+
import { Icon, IconNames } from '../Icon'
30+
import { VisuallyHidden } from '../VisuallyHidden'
31+
import { SimpleLayoutProps } from '../Layout/utils/simple'
32+
33+
export type StatusIntent =
34+
| 'critical'
35+
| 'inform'
36+
| 'neutral'
37+
| 'positive'
38+
| 'warning'
39+
40+
export interface StatusProps
41+
extends CompatibleHTMLProps<HTMLElement>,
42+
SimpleLayoutProps,
43+
TypographyProps {
44+
/**
45+
* @default: 'neutral'
46+
*/
47+
intent?: StatusIntent
48+
}
49+
50+
interface StatusTypeStyling {
51+
accessibilityLabel: string
52+
color: string
53+
icon: IconNames
54+
}
55+
56+
const getStatusIntentStyling = (intent: StatusIntent): StatusTypeStyling => {
57+
switch (intent) {
58+
case 'critical':
59+
return {
60+
accessibilityLabel: 'Critical',
61+
color: 'critical',
62+
icon: 'Error',
63+
}
64+
case 'inform':
65+
return {
66+
accessibilityLabel: 'Inform',
67+
color: 'inform',
68+
icon: 'CircleInfo',
69+
}
70+
case 'positive':
71+
return {
72+
accessibilityLabel: 'Positive',
73+
color: 'positive',
74+
icon: 'CircleCheck',
75+
}
76+
case 'warning':
77+
return {
78+
accessibilityLabel: 'Warning',
79+
color: 'warn',
80+
icon: 'Warning',
81+
}
82+
case 'neutral':
83+
default:
84+
return {
85+
accessibilityLabel: 'Neutral',
86+
color: 'neutral',
87+
icon: 'CircleInfo',
88+
}
89+
}
90+
}
91+
92+
export const Status = forwardRef(
93+
(
94+
{ className, intent = 'neutral' }: StatusProps,
95+
ref: Ref<HTMLInputElement>
96+
) => {
97+
const { accessibilityLabel, color, icon } = getStatusIntentStyling(intent)
98+
const iconProps = {
99+
mr: 'small',
100+
size: 24,
101+
style: { flexBasis: '24px', flexShrink: 0 },
102+
}
103+
return (
104+
<div className={className} ref={ref}>
105+
<Icon color={color} name={icon} {...iconProps} />
106+
<VisuallyHidden>{accessibilityLabel}</VisuallyHidden>
107+
</div>
108+
)
109+
}
110+
)
111+
112+
Status.displayName = 'Status'

0 commit comments

Comments
 (0)