Skip to content

Commit

Permalink
chore(Toaster): add close button label (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogonkov authored Aug 3, 2022
1 parent 79caad6 commit d48b1b9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/components/Toaster/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Icon, IconProps} from '../../Icon';
import {Button} from '../../Button';
import {Alarm, CrossIcon, Info, Success} from '../../icons';
import type {ToastAction, ToastProps, ToastType} from '../types';
import i18n from '../i18n';

import './Toast.scss';

Expand Down Expand Up @@ -212,7 +213,12 @@ export function Toast(props: ToastUnitedProps) {
{renderIcon({type})}
<h3 className={b('title')}>{title}</h3>
{isClosable && (
<Button view="flat-secondary" className={b('btn-close')} onClick={handleClose}>
<Button
view="flat-secondary"
className={b('btn-close')}
onClick={handleClose}
extraProps={{'aria-label': i18n('label_close-button')}}
>
<Icon data={CrossIcon} size={CROSS_ICON_SIZE} />
</Button>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Toaster/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label_close-button": "Close"
}
13 changes: 13 additions & 0 deletions src/components/Toaster/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {registerKeyset} from '../../utils/registerKeyset';
import en from './en.json';
import ru from './ru.json';

const COMPONENT = 'Toaster';

export default registerKeyset(
{
en,
ru,
},
COMPONENT,
);
3 changes: 3 additions & 0 deletions src/components/Toaster/i18n/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label_close-button": "Закрыть"
}
10 changes: 10 additions & 0 deletions src/components/utils/registerKeyset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {i18n} from '../../i18n';
import {Lang} from './configure';

type KeysData = Parameters<typeof i18n.registerKeyset>[2];

export function registerKeyset<T extends KeysData>(data: Record<Lang, T>, keysetName: string) {
Object.entries(data).forEach(([lang, keys]) => i18n.registerKeyset(lang, keysetName, keys));

return i18n.keyset(keysetName);
}
2 changes: 1 addition & 1 deletion test-utils/setup-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {configure as libConfigure, Lang} from '../src/components/utils/configure';
import {configure as libConfigure, Lang} from '../src';
import {configure} from '@testing-library/dom';

libConfigure({
Expand Down

0 comments on commit d48b1b9

Please sign in to comment.