Skip to content

Commit

Permalink
add Token component to Storybook and one more state of this component
Browse files Browse the repository at this point in the history
  • Loading branch information
bsgribtmfu committed Dec 20, 2021
1 parent 3a13f8c commit b2cef87
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/flow-coverage
/build
.idea/
**/.DS_Store
41 changes: 41 additions & 0 deletions src/Components/Token/Token.less
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
-webkit-appearance: none;
appearance: none;
}

&.question {
position: relative;
background-color: transparent;
border: 1px dashed #333;
}
}

.token-remove {
Expand Down Expand Up @@ -67,3 +73,38 @@
}
}
}

.token-question {
margin: 0;
position: absolute;
top: -7px;
left: -7px;
width: 14px;
height: 14px;
border: none;
border-radius: 50%;
background-color: #fff;
border: 1px solid #333;
font-family: inherit;
line-height: inherit;
cursor: pointer;
-webkit-appearance: none;
appearance: none;

&::before,
&::after {
content: '?';
position: absolute;
font-size: 10px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

&:hover {
&::before,
&::after {
opacity: 0.8;
}
}
}
27 changes: 25 additions & 2 deletions src/Components/Token/Token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cn from "./Token.less";

type Props = {
children: string;
type?: "removable" | "selectable";
type?: "removable" | "selectable" | "question";
onClick?: (token: string) => void;
onRemove?: (token: string) => void;
};
Expand Down Expand Up @@ -35,12 +35,35 @@ const Token = (props: Props): React.ReactElement => {
};

return (
<button type="button" className={cn("token", "selectable")} onClick={handleClick}>
<button
type="button"
className={cn("token", "selectable")}
onClick={handleClick}
aria-label="Select"
>
{children}
</button>
);
}

if (type === "question") {
const handleRemove = () => {
onRemove?.(children);
};

return (
<span className={cn("token", "question")}>
{children}
<button
type="button"
className={cn("token-question")}
onClick={handleRemove}
aria-label="Question"
/>
</span>
);
}

return <span className={cn("token")}>{children}</span>;
};

Expand Down
22 changes: 22 additions & 0 deletions src/Stories/Token.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from "react";
import { storiesOf } from "@storybook/react";
import { action } from "@storybook/addon-actions";
import Token from "../Components/Token/Token";

storiesOf("Token", module)
.addDecorator((story) => <div style={{ margin: 20 }}>{story()}</div>)
.add("removable", () => (
<Token type="removable" onRemove={action("onRemove")}>
dev
</Token>
))
.add("selectable", () => (
<Token type="selectable" onClick={action("handleClick")}>
dev
</Token>
))
.add("question", () => (
<Token type="question" onClick={action("handleClick")}>
dev
</Token>
));

0 comments on commit b2cef87

Please sign in to comment.