-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
A11y design enhancements #6563
A11y design enhancements #6563
Changes from all commits
4e043eb
4cb4de8
bdbd153
d1e8ccc
321ba10
a28dd42
e9320b7
827898e
0782de0
6c84cbb
f1521ef
de96c0f
3bdf885
8095c23
c74bd00
bfe6df8
c245294
c453929
e5550aa
b80728c
0a7146d
71791b5
4426529
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,8 +1,9 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
import { styled } from '@storybook/theming'; | ||
|
||
import { Icons } from '@storybook/components'; | ||
import { Badge, Icons } from '@storybook/components'; | ||
import { CheckResult } from 'axe-core'; | ||
import { RuleType } from '../A11YPanel'; | ||
import { SizeMe } from 'react-sizeme'; | ||
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. We could cut back on the number of dependencies by using https://github.com/storybooks/storybook/blob/next/lib/ui/src/app.js#L4 import ResizeDetector from 'react-resize-detector'; 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. That's a good point. I hadn't spotted that in the repo. It looks like it also has the "refreshMode" feature so it fits the needs. Ill convert what I have to use react-resize-detector. Thanks! 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. So I tried the react-resize-detector and there is a delay between when you start an action and the resizing occurs. Think we should switch back to ResizeMe where this did not occur. react-sizeme does an initial, invisible render of the component to measure its size. Then, when the component renders, the size is known and the component can render properly from the beginning. 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 tried switching out the react-resize-detector for resize me but for that use case, react-resize-detector was the better library 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. @ndelangen what do you think about keeping both? |
||
|
||
const impactColors = { | ||
minor: '#f1c40f', | ||
|
@@ -15,18 +16,33 @@ const impactColors = { | |
const List = styled.div({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
padding: '4px', | ||
paddingBottom: '4px', | ||
paddingRight: '4px', | ||
paddingTop: '4px', | ||
fontWeight: '400', | ||
} as any); | ||
|
||
const Item = styled.div({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
marginBottom: '6px', | ||
const Item = styled.div(({ elementWidth }: { elementWidth: number }) => { | ||
const maxWidthBeforeBreak = 407; | ||
return { | ||
flexDirection: elementWidth > maxWidthBeforeBreak ? 'row' : 'inherit', | ||
marginBottom: elementWidth > maxWidthBeforeBreak ? '6px' : '12px', | ||
display: elementWidth > maxWidthBeforeBreak ? 'flex' : 'block', | ||
}; | ||
}); | ||
|
||
const StyledBadge = styled(Badge)(({ status }: { status: string }) => ({ | ||
padding: '2px 8px', | ||
marginBottom: '3px', | ||
minWidth: '65px', | ||
maxWidth: 'fit-content', | ||
width: '100%', | ||
textAlign: 'center', | ||
})); | ||
|
||
const Message = styled.div({ | ||
paddingLeft: '6px', | ||
paddingRight: '23px', | ||
}); | ||
|
||
const Status = styled.div(({ passes, impact }: { passes: boolean; impact: string }) => ({ | ||
|
@@ -40,30 +56,63 @@ const Status = styled.div(({ passes, impact }: { passes: boolean; impact: string | |
}, | ||
})); | ||
|
||
export enum ImpactValue { | ||
MINOR = 'minor', | ||
MODERATE = 'moderate', | ||
SERIOUS = 'serious', | ||
CRITICAL = 'critical', | ||
} | ||
|
||
interface RuleProps { | ||
rule: CheckResult; | ||
passes: boolean; | ||
} | ||
|
||
const Rule: FunctionComponent<RuleProps> = ({ rule, passes }) => ( | ||
<Item> | ||
<Status passes={passes || undefined} impact={rule.impact}> | ||
{passes ? <Icons icon="check" /> : <Icons icon="cross" />} | ||
</Status> | ||
<Message>{rule.message}</Message> | ||
</Item> | ||
); | ||
const formatSeverityText = (severity: string) => { | ||
return severity | ||
.charAt(0) | ||
.toUpperCase() | ||
.concat(severity.slice(1)); | ||
}; | ||
|
||
const Rule: FunctionComponent<RuleProps> = ({ rule }) => { | ||
let badgeType: any = null; | ||
switch (rule.impact) { | ||
case ImpactValue.CRITICAL: | ||
badgeType = 'critical'; | ||
break; | ||
case ImpactValue.SERIOUS: | ||
badgeType = 'negative'; | ||
break; | ||
case ImpactValue.MODERATE: | ||
badgeType = 'warning'; | ||
break; | ||
case ImpactValue.MINOR: | ||
badgeType = 'neutral'; | ||
break; | ||
default: | ||
break; | ||
} | ||
Armanio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<SizeMe refreshMode="debounce"> | ||
{({ size }: { size: any }) => ( | ||
<Item elementWidth={size.width}> | ||
<StyledBadge status={badgeType}>{formatSeverityText(rule.impact)}</StyledBadge> | ||
<Message>{rule.message}</Message> | ||
</Item> | ||
)} | ||
</SizeMe> | ||
); | ||
}; | ||
|
||
interface RulesProps { | ||
rules: CheckResult[]; | ||
passes: boolean; | ||
} | ||
|
||
export const Rules: FunctionComponent<RulesProps> = ({ rules, passes }) => { | ||
export const Rules: FunctionComponent<RulesProps> = ({ rules }) => { | ||
return ( | ||
<List> | ||
{rules.map((rule, index) => ( | ||
<Rule passes={passes} rule={rule} key={index} /> | ||
<Rule rule={rule} key={index} /> | ||
))} | ||
</List> | ||
); | ||
|
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.
is this
id
used anywhere?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.
suggest:
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.
after I modified the array of types, its back to being lowercase by default and only the first char is capitalized in the title. Not sure if the id is being used but I can check.
UPDATE: the Id is used in the TooltipLinkList: key={id || (title as string)}