Skip to content
Open
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
40 changes: 20 additions & 20 deletions src/popup/components/Tabs/Tabs.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
.tab-navigation {
width: 80%;
height: 26px;
// height: 32px;
// padding: 3px;
background-color: #efefef;
border-radius: 13px;
display: flex;
align-items: center;
position: relative;
margin: 0 auto;

&__selector {
position: absolute;
border-radius: 11px;
// width: 100%;
background-color: #fff;
transition: left 300ms ease, background-color 200ms ease;
position: absolute;
height: 22px;
top: 2px;
left: 2px;

&--active {
background-color: #fff;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.15);
}
}

&__item {
flex: 1;
display: flex;
Expand All @@ -33,30 +51,12 @@
input {
display: none;

& + label::before {
content: "";
left: 0;
z-index: -1;
border-radius: 11px;
width: 100%;
background-color: #fff0;
transition: background-color 200ms ease;
position: absolute;
height: 22px;
top: 0;
}

&:not(:checked) + label:active {
&:not(:checked) {
opacity: 0.5;
}

&:checked {
+ label {
&::before {
background-color: #fff;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.15);
}

&:active {
transform: scale(0.95);
}
Expand Down
50 changes: 31 additions & 19 deletions src/popup/components/Tabs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useMemo } from 'react';

import { Tab } from '../../../shared/enums/Tab';

Expand All @@ -10,23 +10,35 @@ interface Props {
onChange(value: Tab): void;
}

const Tabs: React.FC<Props> = ({ items, active, onChange }) => (
<nav className="tab-navigation">
{Object.entries(items).map(([key, value]) => (
<div className="tab-navigation__item" key={key}>
<input
name={name}
value={key}
type="radio"
id={key}
checked={active === key}
onChange={(e) => onChange(e.target.value as Tab)}
/>

<label htmlFor={key}>{value}</label>
</div>
))}
</nav>
);
const Tabs: React.FC<Props> = ({ items, active, onChange }) => {
const [position, setPosition] = useState(0);

const size = useMemo(() => 100, []);

return (
<nav className="tab-navigation">
<div
className="tab-navigation__selector"
style={{ width: size, left: size * Object.keys(items).indexOf(active) }}
/>

{Object.entries(items).map(([key, value]) => (
<div className="tab-navigation__item" key={key}>
<input
name={name}
value={key}
type="radio"
id={key}
checked={active === key}
onClick={(e) => console.log(e.target)}
onChange={(e) => onChange(e.target.value as Tab)}
/>

<label htmlFor={key}>{value}</label>
</div>
))}
</nav>
);
};

export default Tabs;