Skip to content

Commit

Permalink
feat(i18n): breadcrumb and accordion
Browse files Browse the repository at this point in the history
  • Loading branch information
Gergely Nemeth committed Feb 25, 2019
1 parent bdb6726 commit 095db3b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 28 deletions.
19 changes: 19 additions & 0 deletions src/accordion/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright (c) 2018 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow

export type AccordionLocaleT = {|
collapse: string,
expand: string,
|};

const locale = {
collapse: 'Collapse',
expand: 'Expand',
};

export default locale;
57 changes: 32 additions & 25 deletions src/accordion/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LICENSE file in the root directory of this source tree.
*/
// @flow
import * as React from 'react';
import {LocaleContext} from '../locale/index.js';
import {getOverrides, mergeOverrides} from '../helpers/overrides.js';
import {
Plus as PlusIcon,
Expand Down Expand Up @@ -91,31 +92,37 @@ class Panel extends React.Component<PanelPropsT> {
);
const ToggleIconComponent = expanded ? CheckIndeterminateIcon : PlusIcon;
return (
<PanelContainer {...sharedProps} {...panelContainerProps}>
<Header
tabIndex={0}
role="button"
aria-expanded={expanded}
aria-disabled={disabled || null}
{...sharedProps}
{...headerProps}
onClick={this.onClick}
onKeyDown={this.onKeyDown}
>
{title}
<ToggleIconComponent
size={16}
title={expanded ? 'Collapse' : 'Expand'}
{...sharedProps}
{...toggleIconProps}
// $FlowFixMe
overrides={toggleIconOverrides}
/>
</Header>
<Content {...sharedProps} {...contentProps}>
{children}
</Content>
</PanelContainer>
<LocaleContext.Consumer>
{locale => (
<PanelContainer {...sharedProps} {...panelContainerProps}>
<Header
tabIndex={0}
role="button"
aria-expanded={expanded}
aria-disabled={disabled || null}
{...sharedProps}
{...headerProps}
onClick={this.onClick}
onKeyDown={this.onKeyDown}
>
{title}
<ToggleIconComponent
size={16}
title={
expanded ? locale.accordion.collapse : locale.accordion.expand
}
{...sharedProps}
{...toggleIconProps}
// $FlowFixMe
overrides={toggleIconOverrides}
/>
</Header>
<Content {...sharedProps} {...contentProps}>
{children}
</Content>
</PanelContainer>
)}
</LocaleContext.Consumer>
);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/breadcrumbs/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LICENSE file in the root directory of this source tree.

import React, {Children} from 'react';

import {LocaleContext} from '../locale/index.js';
import type {BreadcrumbsPropsT} from './types.js';
import {StyledRoot, StyledSeparator, StyledIcon} from './styled-components.js';
import {getOverrides} from '../helpers/overrides.js';
Expand Down Expand Up @@ -37,9 +38,13 @@ function Breadcrumbs({children, overrides = {}}: BreadcrumbsPropsT) {
});

return (
<Root aria-label="Breadcrumbs navigation" {...baseRootProps}>
{childrenWithSeparators}
</Root>
<LocaleContext.Consumer>
{locale => (
<Root aria-label={locale.breadcrumb.ariaLabel} {...baseRootProps}>
{childrenWithSeparators}
</Root>
)}
</LocaleContext.Consumer>
);
}

Expand Down
17 changes: 17 additions & 0 deletions src/breadcrumbs/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright (c) 2018 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow

export type BreadcrumbLocaleT = {|
ariaLabel: string,
|};

const locale = {
ariaLabel: 'Breadcrumbs navigation',
};

export default locale;
4 changes: 4 additions & 0 deletions src/locale/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ LICENSE file in the root directory of this source tree.
*/
// @flow

import accordion from '../accordion/locale.js';
import breadcrumb from '../breadcrumb/locale.js';
import datepicker from '../datepicker/locale.js';

const en_US = {
accordion,
breadcrumb,
datepicker,
};

Expand Down
4 changes: 4 additions & 0 deletions src/locale/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ LICENSE file in the root directory of this source tree.
*/
// @flow

import type {AccordionLocaleT} from '../accordion/locale.js';
import type {BreadcrumbLocaleT} from '../breadcrumb/locale.js';
import type {DatepickerLocaleT} from '../datepicker/locale.js';

export type LocaleT = {|
accordion: AccordionLocaleT,
breadcrumb: BreadcrumbLocaleT,
datepicker: DatepickerLocaleT,
|};

0 comments on commit 095db3b

Please sign in to comment.