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

[FRNT- 450] Rewrite menulist #85

Merged
merged 10 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
119 changes: 65 additions & 54 deletions src/ui/atoms/header-panel/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,75 @@ import { CloseIcon } from 'icons';
`HeaderPanel` is a navigation component that displays information and actions relating to the current screen.

<Playground>
<div style={{marginBottom: "10px"}}>
<HeaderPanel>Hello! It`s a HeaderPanel</HeaderPanel>
</div>
<div style={{ marginBottom: '10px' }}>
<HeaderPanel>Hello! It`s a HeaderPanel</HeaderPanel>
</div>
</Playground>

### Example

<Playground>
<State initial={false} change={(i) => !i}>
{(value, change) => (
<block.S style={{marginBottom: "10px"}}>
<HeaderPanel>
<div style={{paddingRight: "10px"}}>
<Button onClick={change} text="Sign in" variant="primary" />
</div>
<div>
<b><a href="" target="" style={{paddingRight: "10px"}}>This is a link</a></b>
<b><a href="" target="" style={{paddingRight: "10px"}}>This is a link</a></b>
<b><a href="" target="" >This is a link</a></b>
</div>
</HeaderPanel>
<div
style={{
position: 'absolute',
visibility: value ? 'visible' : 'hidden',
width: value ? '250px' : '0',
marginTop: '20px',

}}>
<Surface>
<FormBlock>
<Label variant="base">Name</Label>
<Input
name="name"
onChange={(event) => console.info('On input change')}
placeholder="Ivan Ivanov"
type="text"
variant="base"
/>
<Label variant="base">Password</Label>
<Input
name="password"
onChange={(event) => console.info('On input change')}
type="password"
variant="base"
/>
<Button
style={{ marginTop: '20px' }}
onClick={() => {}}
text="Sign in"
variant="primary"
/>
</FormBlock>
</Surface>
</div>
</block.S>
)}
</State>
<State initial={false} change={(i) => !i}>
{(value, change) => (
<block.S style={{ marginBottom: '10px' }}>
<HeaderPanel>
<div style={{ paddingRight: '10px' }}>
<Button onClick={change} text="Sign in" variant="primary" />
</div>
<div>
<b>
<a href="" target="" style={{ paddingRight: '10px' }}>
This is a link
</a>
</b>
<b>
<a href="" target="" style={{ paddingRight: '10px' }}>
This is a link
</a>
</b>
<b>
<a href="" target="">
This is a link
</a>
</b>
</div>
</HeaderPanel>
<div
style={{
position: 'absolute',
visibility: value ? 'visible' : 'hidden',
width: value ? '250px' : '0',
marginTop: '20px',
}}
>
<Surface>
<FormBlock>
<Label variant="base">Name</Label>
<Input
name="name"
onChange={(event) => console.info('On input change')}
placeholder="Ivan Ivanov"
type="text"
variant="base"
/>
<Label variant="base">Password</Label>
<Input
name="password"
onChange={(event) => console.info('On input change')}
type="password"
variant="base"
/>
<Button
style={{ marginTop: '20px' }}
onClick={() => {}}
text="Sign in"
variant="primary"
/>
</FormBlock>
</Surface>
</div>
</block.S>
)}
</State>
</Playground>

### Kinds
Expand Down
158 changes: 95 additions & 63 deletions src/ui/atoms/list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import * as React from 'react';
import styled, { StyledComponent } from 'styled-components';
import { Variant } from 'lib/types';

/**
* --woly-list-padding
* --woly-list-color
* --woly-list-background
* --woly-rounding
* --woly-shadow
* --woly-canvas
* --woly-background-hover
* --woly-color
* --woly-color-hover
* --woly-line-height
*/

import { keyboardEventHandle } from 'lib';
interface List {
className?: string;
list: Array<{
Expand All @@ -23,97 +10,142 @@ interface List {
text: React.ReactNode;
id: string;
disabled?: boolean;
onClick?: React.MouseEventHandler<HTMLLIElement>;
onClick: React.EventHandler<React.SyntheticEvent>;
}>;
}

const ListBase: React.FC<List & Variant> = ({ className, list, variant = 'default' }) => (
const ListBase: React.FC<List & Variant> = ({ className, list, variant = 'default', ...p }) => (
<ul className={className} data-variant={variant}>
{list.map(({ left, right, text, id, disabled, onClick }) => (
<li
key={id}
data-type="list-item"
data-disabled={disabled}
onClick={onClick}
>
{left && <span data-icon="left">{left}</span>}
<span data-block="content">{text}</span>
{right && <span data-icon="right">{right}</span>}
</li>
))}
{list.map(({ left, right, text, id, disabled = 'false', onClick }) => {
const tabIndex = disabled ? -1 : 0;
Irinaristova marked this conversation as resolved.
Show resolved Hide resolved

const onKeyDown = React.useCallback(
(event: React.KeyboardEvent) => {
console.log(1);
Irinaristova marked this conversation as resolved.
Show resolved Hide resolved

if (event.key === 'Enter') {
event.preventDefault();
}
const keyHandler = {
enter: (event: React.SyntheticEvent<Element, Event>) => {
onClick(event);
},
};

keyboardEventHandle({
event,
keyHandler,
});
},
[onClick],
);

return (
<li
data-disabled={disabled}
data-type="list-item"
key={id}
onClick={onClick}
onKeyDown={onKeyDown}
tabIndex={tabIndex}
>
{left && <span data-icon="left">{left}</span>}
<span data-text="text">{text}</span>
{right && <span data-icon="right">{right}</span>}
</li>
);
})}
</ul>
);

export const List = styled(ListBase)`
--woly-vertical: calc(1px * var(--woly-component-level) * var(--woly-main-level));
--woly-horizontal: calc(
var(--woly-const-m) + (1px * var(--woly-main-level)) + var(--woly-vertical)
--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)
);

--woly-width: 100%;
--local-gap: var(--local-vertical);
--local-compensate: var(--woly-const-m);
--local-margin: var(--woly-border-width);

--local-color: var(--woly-canvas-text-default);
--local-background: var(--woly-shape-text-default);
--local-item-background: var(--woly-canvas-default);
--local-border: var(--woly-canvas-default);

box-sizing: border-box;
width: var(--woly-width);

width: 100%;

padding: 0;
margin: 0;

color: var(--woly-color, #000000);
border: var(--woly-border-width) solid var(--local-border);

list-style-type: none;
background-color: var(--woly-canvas, #ffffff);
border-radius: var(--woly-rounding, 3px);
box-shadow: var(--woly-shadow, 3px 3px 8px rgba(11, 31, 53, 0.04));

[data-icon] {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;

width: var(--woly-line-height, 24px);
height: var(--woly-line-height, 24px);
padding-right: 6px;

svg > path {
fill: var(--woly-color-disabled, #000000);
}
}

li[data-type='list-item'] {
display: flex;
flex: 1;
align-items: center;

padding: var(--woly-vertical, 12px) var(--woly-horizontal, 18px 12px);
padding: var(--local-vertical) 0;
margin-bottom: var(--local-margin);

font-size: var(--woly-font-size, 15px);
line-height: var(--woly-line-height, 24px);

color: var(--local-color);
background: var(--local-item-background);

cursor: pointer;
outline: none;

[data-block='content'] {
[data-text] {
display: flex;
flex: 1;
padding: 0 var(--local-horizontal);
}

&:hover {
background-color: var(--woly-background-hover, #f5f5f5);
[data-icon] {
--local-icon-size: var(--woly-line-height);
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
padding: 0 calc(var(--local-horizontal) - var(--local-compensate));

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

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

&:focus,
[data-icon='left'] ~ [data-text],
Irinaristova marked this conversation as resolved.
Show resolved Hide resolved
[data-text] ~ [data-icon='right'] {
padding-left: var(--local-gap);
}

&:hover {
--local-item-background: var(--woly-canvas-disabled);
}
&:focus {
box-shadow: 0 0 0 1.5px var(--woly-focus);
}
&:active {
border-color: var(--woly-border-focus, #1f68f5);
border-style: solid;
border-width: var(--woly-border-width, 1.5px);
--local-item-background: var(--woly-focus);
--local-color: var(--woly-shape-text-active);
}

&[data-disabled='true'] {
color: var(--woly-color-disabled, #c4c4c4);
--local-color: var(--woly-canvas-text-disabled);

pointer-events: none;

[data-icon] {
svg > path {
fill: var(--woly-canvas, #c4c4c4);
--local-color: var(--woly-canvas-text-disabled);
}
}
}
Expand Down
Loading