Skip to content

Commit

Permalink
feat: pass pass thru valid attributes in #icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Jan 25, 2019
1 parent 18b16f2 commit 6eded20
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Keyboard shortcuts can increase task efficiency.

##### Progressive enhancement

Forms, navigation and other essential components and actions should work on older browsers and devices. Styling comes second to content and accessibilty.
Forms, navigation and other essential components and actions should work on older browsers and devices. Styling comes second to content and accessibility.

#### Understandable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ class LiveCode extends PureComponent {
</>
)}
<Toolbar>
{!hideCode && (
<LiveError className="dnb-form-status dnb-form-status--text dnb-form-status--error" />
)}
{hidePreview && (
<Button
className="toggle-button"
Expand All @@ -162,6 +159,9 @@ class LiveCode extends PureComponent {
)}
</Toolbar>
{!hideCode && <LiveEditor language="jsx" />}
{!hideCode && (
<LiveError className="dnb-form-status dnb-form-status--text dnb-form-status--error" />
)}
</LiveProvider>
</LiveCodeEditor>
)
Expand Down Expand Up @@ -192,6 +192,13 @@ const LiveCodeEditor = styled.div`
border-color: transparent transparent #222 transparent;
}
}
.dnb-form-status:last-child {
max-width: 40rem;
height: auto;
white-space: normal;
line-height: var(--input-height);
}
`

const Toolbar = styled.div`
Expand All @@ -208,18 +215,11 @@ const Toolbar = styled.div`
padding: 0 1rem 1rem;
pointer-events: none;
${'' /* pointer-events: none;
button,
.dnb-form-status {
pointer-events: all;
}
.dnb-form-status {
max-width: 40rem;
height: auto;
white-space: normal;
line-height: var(--input-height);
}
} */}
`

/** Removes the last token from a code example if it's empty. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { getComponents } from 'dnb-ui-lib/src/components'

const ComponentBox = ({ children, scope = {}, ...rest }) => {
return (
<CodeBlock
scope={{ ...getComponents(), styled, React, ...scope }}
{...rest}
>
<CodeBlock scope={{ ...getComponents(), styled, ...scope }} {...rest}>
{children}
</CodeBlock>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class ListItem extends PureComponent {
>
<span>
{icon && graphics[icon] && (
<Icon icon={graphics[icon]} size="medium" />
<Icon icon={graphics[icon]} size="medium" aria_hidden />
)}
{children}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ export default class StickyMenuBar extends PureComponent {
on_click={this.toggleMenuHandler}
>
{/* <Logo height={48} /> */}
<Icon icon={PortalLogo} size={48} />
<Icon icon={PortalLogo} size={48} aria_hidden />
{slogan}
<IconPrimary icon="chevron_down" size="small" />
<IconPrimary
icon="chevron_down"
size="small"
aria_hidden
/>
</Button>

<span>
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class Content extends PureComponent {
icon={icon}
size={icon_size}
alt={alt}
area_hidden={isIconOnly ? false : Boolean(alt)}
aria_hidden={isIconOnly ? false : Boolean(alt)}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports[`Button component have to match default button snapshot 1`] = `
</span>
<IconPrimary
alt="This is a button title"
area_hidden={true}
aria_hidden={true}
attributes={null}
class={null}
className="dnb-button__icon"
Expand All @@ -75,11 +75,10 @@ exports[`Button component have to match default button snapshot 1`] = `
width={null}
>
<span
aria-hidden={true}
aria-hidden="true"
aria-label="This is a button title"
className="dnb-icon dnb-button__icon"
role="img"
title={null}
>
<question>
<svg
Expand Down Expand Up @@ -163,7 +162,7 @@ exports[`Button component have to match href="..." snapshot 1`] = `
</span>
<IconPrimary
alt="This is a button title"
area_hidden={true}
aria_hidden={true}
attributes={null}
class={null}
className="dnb-button__icon"
Expand All @@ -177,11 +176,10 @@ exports[`Button component have to match href="..." snapshot 1`] = `
width={null}
>
<span
aria-hidden={true}
aria-hidden="true"
aria-label="This is a button title"
className="dnb-icon dnb-button__icon"
role="img"
title={null}
>
<question>
<svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`Dropdown component have to match snapshot 1`] = `
>
<IconPrimary
alt={null}
area_hidden={false}
aria_hidden={false}
attributes={null}
class={null}
className={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`FormStatus component have to match snapshot 1`] = `
>
<IconPrimary
alt={null}
area_hidden={false}
aria_hidden={false}
attributes={null}
class={null}
className={null}
Expand All @@ -37,7 +37,6 @@ exports[`FormStatus component have to match snapshot 1`] = `
aria-label="exclamation"
className="dnb-icon"
role="img"
title={null}
>
<exclamation>
<svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`IconPrimary component have to match snapshot 1`] = `
<IconPrimary
alt={null}
area_hidden={false}
aria_hidden={false}
attributes={null}
class={null}
className={null}
Expand All @@ -19,17 +19,11 @@ exports[`IconPrimary component have to match snapshot 1`] = `
aria-label="question"
className="dnb-icon dnb-icon--default"
role="img"
title={null}
>
<question
height={null}
width={null}
>
<question>
<svg
fill="none"
height={null}
viewBox="0 0 16 16"
width={null}
>
<path
clipRule="evenodd"
Expand Down
29 changes: 16 additions & 13 deletions packages/dnb-ui-lib/src/components/icon/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const propTypes = {
color: PropTypes.string,
alt: PropTypes.string,
title: PropTypes.string,
area_hidden: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
aria_hidden: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
attributes: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
class: PropTypes.string,
// React props
Expand All @@ -60,7 +60,7 @@ export const defaultProps = {
color: null,
alt: null,
title: null,
area_hidden: false,
aria_hidden: false,
attributes: null,
class: null,
// React props
Expand Down Expand Up @@ -224,19 +224,24 @@ export default class Icon extends PureComponent {
}

static prerender(props) {
const icon = Icon.getIcon(props)

const {
icon,
size,
color,
modifier,
alt: _alt,
title,
class: _className,
className,
area_hidden
aria_hidden,
...attributes
} = props

const { sizeAsString, svgParams } = Icon.calcSize(props)
const { sizeAsString, svgParams } = Icon.calcSize({
icon, // because to have a clean "attributes"
size, // because to have a clean "attributes"
...props
})

if (color) {
svgParams.color = color
Expand All @@ -254,16 +259,14 @@ export default class Icon extends PureComponent {
// also used for code markup simulation
const wrapperParams = validateDOMAttributes(props, {
role: 'img',
// as we use aria-label, we do not provide an alt as well
// because we use aria-label, we do not provide an alt as well
// alt,
['aria-label']: alt,
title
['aria-hidden']: aria_hidden ? 'true' : null,
title,
...attributes
})

if (area_hidden) {
// wrapperParams['role'] = 'presentation' // almost the same as aria-hidden
wrapperParams['aria-hidden'] = area_hidden
}
wrapperParams.className = classnames(
'dnb-icon',
modifier ? `dnb-icon--${modifier}` : null,
Expand All @@ -274,7 +277,7 @@ export default class Icon extends PureComponent {

return {
...props,
icon,
icon: Icon.getIcon(props),
alt,
svgParams,
wrapperParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Icon component have to match snapshot 1`] = `
<Icon
alt="alt"
area_hidden={true}
aria_hidden={true}
attributes="attributes"
class="class"
className="className"
Expand All @@ -16,11 +16,14 @@ exports[`Icon component have to match snapshot 1`] = `
width="width"
>
<span
aria-hidden={true}
aria-hidden="true"
aria-label="alt"
attributes="attributes"
className="dnb-icon dnb-icon--modifier class className"
height="height"
role="img"
title="title"
width="width"
>
<SvgComponent
color="color"
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/src/components/icon/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
| `size` | _(optional)_ the dimension of the icon. This will be the `viewBox` and represent `width` and `height`. Defaults to `16`. You can use `small`,`medium` or `large` |
| `color` | _(optional)_ sets a color property to the `svg` markup. Default is no color, witch means _black_ |
| `modifier` | _(optional)_ modifier class to define e.g. sizes. |
| `area_hidden` | _(optional)_ To declare that the icon should not be visible to screen readers. |
| `aria_hidden` | _(optional)_ To declare that the icon should not be visible to screen readers. Can also be defined as `aria-hidden`. |
| `attributes` | _(optional)_ insert any other attributes. For example `disabled` or any other custom attributes. |
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ exports[`Input component have to match type="search" snapshot 1`] = `
>
<input
aria-describedby="id-description"
autoComplete={null}
className="dnb-input__input input_class"
id="id"
name="id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ exports[`Modal component have to match snapshot 1`] = `
>
<button
className="dnb-button dnb-button--secondary dnb-button--size-medium dnb-button--icon-position-right dnb-button--has-icon"
id={null}
onClick={[Function]}
onMouseOut={[Function]}
title="Open Modal"
Expand Down Expand Up @@ -121,7 +120,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<IconPrimary
alt="Open Modal"
area_hidden={false}
aria_hidden={false}
attributes={null}
class={null}
className="dnb-button__icon"
Expand All @@ -138,17 +137,11 @@ exports[`Modal component have to match snapshot 1`] = `
aria-label="Open Modal"
className="dnb-icon dnb-icon--default dnb-button__icon"
role="img"
title={null}
>
<question
height={null}
width={null}
>
<question>
<svg
fill="none"
height={null}
viewBox="0 0 16 16"
width={null}
>
<path
clipRule="evenodd"
Expand Down Expand Up @@ -336,7 +329,6 @@ exports[`Modal component have to match snapshot 1`] = `
>
<button
className="dnb-button dnb-button--secondary dnb-button--size-medium dnb-button--icon-position-right dnb-button--has-icon dnb-modal__close-button"
id={null}
onClick={[Function]}
onMouseOut={[Function]}
title="Close"
Expand Down Expand Up @@ -366,7 +358,7 @@ exports[`Modal component have to match snapshot 1`] = `
>
<IconPrimary
alt="Close"
area_hidden={false}
aria_hidden={false}
attributes={null}
class={null}
className="dnb-button__icon"
Expand All @@ -383,17 +375,11 @@ exports[`Modal component have to match snapshot 1`] = `
aria-label="Close"
className="dnb-icon dnb-icon--default dnb-button__icon"
role="img"
title={null}
>
<close
height={null}
width={null}
>
<close>
<svg
fill="none"
height={null}
viewBox="0 0 16 16"
width={null}
>
<path
clipRule="evenodd"
Expand Down
Loading

0 comments on commit 6eded20

Please sign in to comment.