Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

[FRNT- 456] Implement radio button #103

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/box-styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const Global = styled.div`

/* should be rewritten to formulas */
--woly-line-height: 24px;
--woly-border-width: 1.5px;
--woly-border-width: 2px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я правильно понимаю, что ты меняешь тут значение для radio button?

У primary не прописана ширина бордера и этот вариант берет ширину отсюда. надо бы прокинуть для primary ширину бордера.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем менять ширину бордеров отдельно для primary?

Ширина бордеров должна быть везде одинакова, поэтому она не в variants

--woly-rounding: 4px;
--woly-font-size: 15px;

Expand All @@ -42,7 +42,7 @@ export const Global = styled.div`
--woly-canvas-default: transparent;
--woly-canvas-disabled: var(--palette-snow-100);
--woly-canvas-hover: var(--palette-snow-500);
--woly-canvas-active: var(--palette-snow-500);
--woly-canvas-active: var(--palette-lavender-500);

--woly-canvas-text-default: var(--palette-snow-1000);
--woly-canvas-text-disabled: var(--palette-snow-500);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/atoms/input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import styled, { StyledComponent } from 'styled-components';
import { Variant } from 'lib/types';

import { InputContainer, InputElement } from '../../elements/quarks';

interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
Expand Down Expand Up @@ -52,12 +53,11 @@ export const Input = styled(InputBase)`
--local-horizontal: calc(
var(--woly-const-m) + (1px * var(--woly-main-level)) + var(--local-vertical)
);

box-sizing: border-box;
width: 100%;

&[data-disabled='true'] {
pointer-events: none;
}

` as StyledComponent<'div', Record<string, unknown>, InputProps & Variant>;
61 changes: 29 additions & 32 deletions src/ui/atoms/input/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { ButtonIcon } from '../../atoms';
`Input` is a field to accept data from the user. Input is used to create form fields that accept user input.
They typically appear in forms and dialogs.

Inputs requiring certain data formats such as numbers, e-mail addresses or passwords are declared accordingly.
Inputs requiring certain data formats such as numbers, e-mail addresses or passwords are declared accordingly.
This makes it easier for the user to enter information using a virtual keyboard.

When a input is active or contains an error, the input’s border color and thickness vary.

## Placeholder text (Hint text)

Placeholder text rests in the input field until the user starts entering text.
Placeholder text rests in the input field until the user starts entering text.
It may contain an action or an example, such as a phone number or email address.

## Helper text
Expand All @@ -35,10 +35,9 @@ Specs:
- Left justified
- On a single line if possible, or with text wrapping (if multiple lines)


## Error message

When input isn’t accepted, text fields can display an error message below the input line, with instructions on how to fix the error.
When input isn’t accepted, text fields can display an error message below the input line, with instructions on how to fix the error.
Until the error is fixed, the error replaces the helper text.

An error message should appear on a single line, if possible.
Expand All @@ -52,7 +51,6 @@ Specs:
- Right justified
- Displayed as a ratio of characters used and the character limit (formatted as: characters used / character limit)


### Example

<Playground>
Expand All @@ -69,7 +67,7 @@ Specs:

Disabled text fields are uneditable. They have less opacity so that they appear less tappable.

<Playground direction='vertical'>
<Playground direction="vertical">
<Input
disabled
name="name"
Expand All @@ -89,7 +87,7 @@ Disabled text fields are uneditable. They have less opacity so that they appear
/>
</Playground>

### Icons
### Icons

Inputs can be combined with an icon on the left side or the right. Use icons on the both sides is not recommended.

Expand Down Expand Up @@ -121,10 +119,10 @@ Inputs can be combined with an icon on the left side or the right. Use icons on
/>
</Playground>

Icons can also be touch targets for nested components.
Icons can also be touch targets for nested components.

<Playground size="L" direction="vertical">
<Input
<Input
rightIcon={
<block.S>
<ButtonIcon
Expand All @@ -140,7 +138,7 @@ Icons can also be touch targets for nested components.
onChange={(event) => console.info('On input change')}
variant="primary"
/>
<Input
<Input
leftIcon={<InfoIcon />}
type="text"
name="name"
Expand All @@ -162,9 +160,10 @@ Icons can also be touch targets for nested components.
### Variants

Primary and secondary variants are should be used to focus user attention.

<!-- example for secondary variant will be fixed with task FRNT-477 -->

<Playground direction='vertical'>
<Playground direction="vertical">
<Input
leftIcon={<InfoIcon />}
name="name"
Expand All @@ -185,7 +184,6 @@ Primary and secondary variants are should be used to focus user attention.
/>
</Playground>


Error variant can be used to focus user attention on error.

<Playground>
Expand All @@ -211,7 +209,7 @@ Size controlled by the `component-level` block property not from the props.
placeholder="Enter your name here"
type="text"
variant="primary"
/>
/>
</block.S>
<block.M>
<Input
Expand All @@ -220,7 +218,7 @@ Size controlled by the `component-level` block property not from the props.
placeholder="Enter your name here"
type="text"
variant="primary"
/>
/>
</block.M>
<block.L>
<Input
Expand All @@ -229,7 +227,7 @@ Size controlled by the `component-level` block property not from the props.
placeholder="Enter your name here"
type="text"
variant="primary"
/>
/>
</block.L>
<block.XL>
<Input
Expand All @@ -238,7 +236,7 @@ Size controlled by the `component-level` block property not from the props.
placeholder="Enter your name here"
type="text"
variant="primary"
/>
/>
</block.XL>
<block.H>
<Input
Expand All @@ -247,7 +245,7 @@ Size controlled by the `component-level` block property not from the props.
placeholder="Enter your name here"
type="text"
variant="primary"
/>
/>
</block.H>
</Playground>

Expand All @@ -265,10 +263,10 @@ Inputs can be placed inside the container. Input width is equal to container siz
placeholder="Enter your name here"
variant="primary"
onChange={(event) => console.info('On input change')}
/>
/>
</block.L>
<block.L>
<Input
<Input
leftIcon={<InfoIcon />}
type="text"
name="name"
Expand All @@ -288,7 +286,6 @@ Inputs can be placed inside the container. Input width is equal to container siz
</block.L>
</Playground>


### Kinds

| Name | Description |
Expand All @@ -297,15 +294,15 @@ Inputs can be placed inside the container. Input width is equal to container siz

### Props

| Name | Type | Default | Description |
| -------------- | ----------------------------------------------------- | ----------- | ----------------------------------------------------------- |
| `type` | `"text" ӏ "password" ӏ "email"` | `text` | HTML type of the input |
| `name` | `string` | | Name attribute specifies a name of the input |
| `value` | `HTMLInputElement['value']` | `null` | Value of input field |
| `onChange` | `React.EventHandler<React.SyntheticEvent>;` | | On change event handler. |
| `variant` | `string` | `'default'` | Variant prop to style Input component |
| `leftIcon` | `React.ReactNode` | | Component to show on the left side of the text (ex.: Icon) |
| `disabled` | `boolean` | | HTML disabled attribute |
| `placeholder` | `string` | | CSS pseudo-element represents the placeholder text |
|`rightIcon` | `React.ReactNode` | | Component to show on the right side of the text (ex.: Icon) |
| `...` | `HTMLInputElement` | `{}` | Other props are inherited from `HTMLInputElement` |
| Name | Type | Default | Description |
| ------------- | ------------------------------------------- | ----------- | ----------------------------------------------------------- |
| `type` | `"text" ӏ "password" ӏ "email"` | `text` | HTML type of the input |
| `name` | `string` | | Name attribute specifies a name of the input |
| `value` | `HTMLInputElement['value']` | `null` | Value of input field |
| `onChange` | `React.EventHandler<React.SyntheticEvent>;` | | On change event handler. |
| `variant` | `string` | `'default'` | Variant prop to style Input component |
| `leftIcon` | `React.ReactNode` | | Component to show on the left side of the text (ex.: Icon) |
| `disabled` | `boolean` | | HTML disabled attribute |
| `placeholder` | `string` | | CSS pseudo-element represents the placeholder text |
| `rightIcon` | `React.ReactNode` | | Component to show on the right side of the text (ex.: Icon) |
| `...` | `HTMLInputElement` | `{}` | Other props are inherited from `HTMLInputElement` |
34 changes: 13 additions & 21 deletions src/ui/elements/quarks/input-container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import * as React from 'react';
import styled, { StyledComponent } from 'styled-components';
import { Variant } from 'lib/types';
import { keyboardEventHandle } from 'lib';
interface InputContainerProps
extends React.InputHTMLAttributes<HTMLInputElement> {
interface InputContainerProps extends React.InputHTMLAttributes<HTMLInputElement> {
className?: string;
disabled?: boolean;
leftIcon?: React.ReactNode;
Expand All @@ -20,12 +19,10 @@ const InputContainerBase: React.FC<InputContainerProps & Variant> = ({
rightIcon,
variant = 'default',
}) => {

const tabIndex = disabled ? -1 : 0;

const onKeyDown = React.useCallback(
(event: React.KeyboardEvent) => {

if (event.key === 'Enter') {
event.preventDefault();
}
Expand Down Expand Up @@ -56,8 +53,7 @@ const InputContainerBase: React.FC<InputContainerProps & Variant> = ({
{rightIcon && <span data-icon="right">{rightIcon}</span>}
</div>
);
}

};

export const InputContainer = styled(InputContainerBase)`
--local-vertical: calc(1px * var(--woly-component-level) * var(--woly-main-level));
Expand Down Expand Up @@ -88,13 +84,13 @@ export const InputContainer = styled(InputContainerBase)`
border: var(--woly-border-width) solid var(--local-border-color);
border-radius: var(--woly-rounding);

[data-input="input"] {
[data-input='input'] {
flex: 1;
color: var(--local-value-color);

padding: 0 var(--local-horizontal);

input{
input {
padding: 0;
}

Expand All @@ -105,17 +101,17 @@ export const InputContainer = styled(InputContainerBase)`

[data-icon] {
--local-icon-size: var(--woly-line-height);

display: flex;
align-items: center;
justify-content: center;

width: var(--local-icon-size);
height: var(--local-icon-size);

svg > path {
fill: var(--local-icon-fill);
}
svg > path {
fill: var(--local-icon-fill);
}
}

[data-icon='left'] {
Expand All @@ -126,8 +122,8 @@ export const InputContainer = styled(InputContainerBase)`
padding: 0 calc(var(--local-horizontal) - var(--local-compensate)) 0 0;
}

[data-icon='left'] ~ [data-input="input"],
[data-input="input"] ~ [data-icon='right'] {
[data-icon='left'] ~ [data-input='input'],
[data-input='input'] ~ [data-icon='right'] {
padding-left: var(--local-gap);
}

Expand All @@ -146,7 +142,7 @@ export const InputContainer = styled(InputContainerBase)`

&:active {
--local-border-color: var(--woly-focus);

[data-icon] {
--local-icon-fill: var(--woly-canvas-text-default);
}
Expand All @@ -159,8 +155,4 @@ export const InputContainer = styled(InputContainerBase)`
--local-border-color: var(--woly-shape-disabled);
--local-value-color: var(--woly-canvas-text-disabled);
}
` as StyledComponent<
'div',
Record<string, unknown>,
InputContainerProps & Variant
>;
` as StyledComponent<'div', Record<string, unknown>, InputContainerProps & Variant>;
3 changes: 1 addition & 2 deletions src/ui/elements/quarks/input-element/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react';
import styled, { StyledComponent } from 'styled-components';

interface InputElementProps
extends React.InputHTMLAttributes<HTMLInputElement> {
interface InputElementProps extends React.InputHTMLAttributes<HTMLInputElement> {
className?: string;
name: string;
onChange: React.EventHandler<React.SyntheticEvent>;
Expand Down
1 change: 1 addition & 0 deletions src/ui/molecules/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { Checkbox } from './checkbox';
export { Field } from './field';
export { InputPassword } from './input-password';
export { RadioButton } from './radio-button';
export { Popover } from './popover';
export { Select } from './select';
export { Switch } from './switch';
18 changes: 8 additions & 10 deletions src/ui/molecules/input-password/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';
import styled, { StyledComponent } from 'styled-components';
import { Variant } from 'lib/types';

import { ButtonIcon, Input } from 'ui';
import { ClosedEyeIcon, InfoIcon, OpenedEyeIcon } from 'icons';
import { Variant } from 'lib/types';
import { block } from 'box-styles';
import { ClosedEyeIcon, OpenedEyeIcon, InfoIcon } from 'icons';

interface InputPasswordProps {
className?: string;
disabled?: boolean;
Expand Down Expand Up @@ -53,19 +53,17 @@ export const InputPasswordBase: React.FC<InputPasswordProps & Variant> = ({
/>
</div>
);
}
};

export const InputPassword = styled(InputPasswordBase)`
export const InputPassword = (styled(InputPasswordBase)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем обертка?

--local-gap: calc(
(1px * var(--woly-main-level)) +
(1px * var(--woly-main-level) * var(--woly-component-level))
(1px * var(--woly-main-level)) + (1px * var(--woly-main-level) * var(--woly-component-level))
);

box-sizing: border-box;
width: 100%;

& > *:not(:first-child) {
margin-left: var(--woly-gap);
}

` as unknown as StyledComponent<'div', Record<string, unknown>, InputPasswordProps & Variant>;
` as unknown) as StyledComponent<'div', Record<string, unknown>, InputPasswordProps & Variant>;
Loading