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

[FRNT-533] Rewrite field to box-model #111

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
13 changes: 13 additions & 0 deletions src/ui/elements/quarks/box/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { css } from 'styled-components';

export const verticalBox = css`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export const verticalBox = css`
export const boxVertical = css`

Мне кажется, лучше именовать от общего к частному.
Общее тут будет box, а его частный случай это vertical. Есть разные боксы, этот конкретно vertical

--local-gap: var(--woly-const-m);

& > *:not(:first-child) {
padding-top: var(--local-gap);
}

& > :only-child {
padding: 0;
}
`;
1 change: 1 addition & 0 deletions src/ui/elements/quarks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { verticalBox } from './box';
export { InputContainer } from './input-container';
export { InputElement } from './input-element';
30 changes: 10 additions & 20 deletions src/ui/molecules/field/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 { box, verticalBox } from 'ui/elements/quarks';

import { Label } from '../../atoms';

Expand All @@ -18,38 +19,27 @@ const FieldBase: React.FC<FieldProps & Variant> = ({
row = false,
variant = 'secondary',
}) => (
<div className={className} data-row={row} data-variant={variant}>
<div data-field="label">
<Label>
{label}
<div data-field="content">{children}</div>
</Label>
</div>
</div>
<Label data-field="label" className={className} data-row={row} data-variant={variant}>
<span>{label}</span>
<div data-field="content">{children}</div>
</Label>
);

export const Field = styled(FieldBase)`
--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)
);

padding-bottom: var(--local-vertical, 6px);
--local-gap: calc(1px * var(--woly-component-level) * var(--woly-main-level));

box-sizing: border-box;

width: 100%;

label {
padding: var(--local-vertical, 6px) 0;
&[data-row='false'] {
${verticalBox}
}

&[data-row='true'] {
display: flex;
align-items: center;

[data-field='label'] {
padding: 0 var(--local-horizontal, 6px);
& > :not(:first-child) {
padding-left: var(--local-gap);
}
}
` as StyledComponent<'label', Record<string, unknown>, FieldProps & Variant>;