Skip to content

Commit

Permalink
feat(radio): add align
Browse files Browse the repository at this point in the history
  • Loading branch information
redzumi committed Jan 13, 2021
1 parent c8e4489 commit fe9faec
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
28 changes: 14 additions & 14 deletions packages/radio-group/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Object {
class="radioList"
>
<label
class="container s my-radio radio"
class="container s start my-radio radio"
>
<input
type="radio"
Expand All @@ -37,7 +37,7 @@ Object {
</span>
</label>
<label
class="container s my-second-radio radio"
class="container s start my-second-radio radio"
>
<input
type="radio"
Expand All @@ -57,7 +57,7 @@ Object {
</span>
</label>
<label
class="container s radio"
class="container s start radio"
>
<input
type="radio"
Expand Down Expand Up @@ -93,7 +93,7 @@ Object {
class="radioList"
>
<label
class="container s my-radio radio"
class="container s start my-radio radio"
>
<input
type="radio"
Expand All @@ -113,7 +113,7 @@ Object {
</span>
</label>
<label
class="container s my-second-radio radio"
class="container s start my-second-radio radio"
>
<input
type="radio"
Expand All @@ -133,7 +133,7 @@ Object {
</span>
</label>
<label
class="container s radio"
class="container s start radio"
>
<input
type="radio"
Expand Down Expand Up @@ -226,7 +226,7 @@ Object {
class="radioList"
>
<label
class="container s my-radio radio"
class="container s start my-radio radio"
>
<input
type="radio"
Expand All @@ -246,7 +246,7 @@ Object {
</span>
</label>
<label
class="container s my-second-radio radio"
class="container s start my-second-radio radio"
>
<input
type="radio"
Expand All @@ -266,7 +266,7 @@ Object {
</span>
</label>
<label
class="container s radio"
class="container s start radio"
>
<input
type="radio"
Expand Down Expand Up @@ -307,7 +307,7 @@ Object {
class="radioList"
>
<label
class="container s my-radio radio"
class="container s start my-radio radio"
>
<input
type="radio"
Expand All @@ -327,7 +327,7 @@ Object {
</span>
</label>
<label
class="container s my-second-radio radio"
class="container s start my-second-radio radio"
>
<input
type="radio"
Expand All @@ -347,7 +347,7 @@ Object {
</span>
</label>
<label
class="container s radio"
class="container s start radio"
>
<input
type="radio"
Expand Down Expand Up @@ -445,7 +445,7 @@ Object {
class="radioList"
>
<label
class="container s radio-group radio"
class="container s start radio-group radio"
>
<input
type="radio"
Expand Down Expand Up @@ -481,7 +481,7 @@ Object {
class="radioList"
>
<label
class="container s radio-group radio"
class="container s start radio-group radio"
>
<input
type="radio"
Expand Down
2 changes: 2 additions & 0 deletions packages/radio/src/Component.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import { name, version } from '../package.json';
const disabled = boolean('disabled', false);
const label = text('label', 'Text label')
const hint = text('hint', 'Hint');
const align = select('align', ['start', 'end', 'center'], 'start');
return (
<Radio
disabled={disabled}
size={size}
align={align}
onChange={handleChange}
checked={checked}
hint={hint}
Expand Down
9 changes: 8 additions & 1 deletion packages/radio/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useFocus } from '@alfalab/hooks';
import styles from './index.module.css';

type NativeProps = InputHTMLAttributes<HTMLInputElement>;
type Align = 'start' | 'end' | 'center';

export type RadioProps = Omit<
NativeProps,
Expand Down Expand Up @@ -51,6 +52,11 @@ export type RadioProps = Omit<
*/
className?: string;

/**
* Выравнивание
*/
align?: Align;

/**
* Обработчик на выбор элемента
*/
Expand All @@ -75,6 +81,7 @@ export const Radio = forwardRef<HTMLLabelElement, RadioProps>(
checked,
hint,
size = 's',
align = 'start',
...restProps
},
ref,
Expand All @@ -92,7 +99,7 @@ export const Radio = forwardRef<HTMLLabelElement, RadioProps>(
return (
// eslint-disable-next-line jsx-a11y/label-has-associated-control
<label
className={cn(styles.container, styles[size], className, {
className={cn(styles.container, styles[size], styles[align], className, {
[styles.disabled]: disabled,
[styles.checked]: checked,
[styles.focused]: focused,
Expand Down
8 changes: 4 additions & 4 deletions packages/radio/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object {
"baseElement": <body>
<div>
<label
class="container s"
class="container s start"
>
<input
type="radio"
Expand All @@ -28,7 +28,7 @@ Object {
</body>,
"container": <div>
<label
class="container s"
class="container s start"
>
<input
type="radio"
Expand Down Expand Up @@ -107,7 +107,7 @@ Object {
"baseElement": <body>
<div>
<label
class="container s"
class="container s start"
>
<input
type="radio"
Expand All @@ -134,7 +134,7 @@ Object {
</body>,
"container": <div>
<label
class="container s"
class="container s start"
>
<input
type="radio"
Expand Down
12 changes: 12 additions & 0 deletions packages/radio/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@
flex-direction: column;
}

.start {
align-items: flex-start;
}

.end {
align-items: flex-end;
}

.center {
align-items: center;
}

.label {
@mixin system_16-24_regular;
color: var(--radio-label-color);
Expand Down

0 comments on commit fe9faec

Please sign in to comment.