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

[FRNT-493] Implement upload area component #107

Merged
merged 4 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/lib/box-styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Global = styled.div`
/* should be rewritten to formulas */
--woly-line-height: 24px;
--woly-border-width: 1.5px;
--woly-rounding: 4px;
--woly-rounding: 3px;
Irinaristova marked this conversation as resolved.
Show resolved Hide resolved
--woly-font-size: 15px;

--woly-const-m: 6px;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/atoms/header-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const HeaderPanel = styled.div.attrs(map)`
);

--local-box-shadow: 3px 3px 9px rgba(57, 57, 57, 0.12);

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

background-color: var(--woly-background);
Expand Down
1 change: 1 addition & 0 deletions src/ui/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export { Table, Thead, Tbody, Tr, Td, Th } from './table';
export { Text } from './text';
export { TextArea } from './text-area';
export { Tooltip } from './tooltip';
export { UploadArea } from './upload-area';
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` |
4 changes: 3 additions & 1 deletion src/ui/atoms/label/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const map = (properties: LabelProps & Variant) => ({

export const Label = styled.label.attrs(map)`
--local-vertical: calc(1px * var(--woly-component-level) * var(--woly-main-level));
--local-horizontal: calc(var(--woly-const-m) + (1px * var(--woly-main-level)) + var(--local-vertical));
--local-horizontal: calc(
var(--woly-const-m) + (1px * var(--woly-main-level)) + var(--local-vertical)
);

--local-color: var(--woly-canvas-text-default);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/atoms/text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const map = (properties: TextProps & Variant) => ({

export const Text = styled.p.attrs(map)`
--local-color: var(--woly-canvas-text-default);

margin: 0;
color: var(--local-color);
font-size: 15px;
Expand Down
64 changes: 64 additions & 0 deletions src/ui/atoms/upload-area/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as React from 'react';
import styled, { StyledComponent } from 'styled-components';
import { Variant } from 'lib/types';

interface UploadAreaProps {
className?: string;
center?: boolean;
content?: React.ReactNode;
}

const UploadAreaBase: React.FC<UploadAreaProps & Variant> = ({
className,
center = false,
content,
variant = 'default',
}) => (
<div className={className} data-variant={variant} tabIndex={0}>
<div data-content data-center={center}>
<div data-overlay />
{content}
</div>
</div>
);

export const UploadArea = styled(UploadAreaBase)`
--local-border-color: var(--woly-canvas-hover);
--local-background-color: var(--woly-canvas-disabled);

width: 100%;
height: 100%;

position: relative;
overflow: auto;

background-color: var(--local-background-color);
border: var(--woly-border-width) dashed var(--local-border-color);
border-radius: var(--woly-rounding);

[data-center='true'] {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

&:focus {
--local-border-color: var(--woly-focus);
--local-background-color: rgba(110, 59, 254, 0.05);
Irinaristova marked this conversation as resolved.
Show resolved Hide resolved
outline: none;

[data-overlay] {
width: 100%;
height: 100%;

position: absolute;
z-index: 1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);

background: rgba(110, 59, 254, 0.05);
Irinaristova marked this conversation as resolved.
Show resolved Hide resolved
}
}
` as StyledComponent<'div', Record<string, unknown>, UploadAreaProps & Variant>;
Loading