From d177e0c7c61845b516d4a361a21739bb6486b9b5 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 1 Apr 2022 19:03:42 +0200 Subject: chore: add a back to top component --- .../atoms/buttons/button-link.stories.tsx | 15 +++++++ src/components/atoms/buttons/button-link.tsx | 18 ++++++-- src/components/atoms/buttons/button.stories.tsx | 15 +++++++ src/components/atoms/buttons/button.tsx | 8 +++- src/components/atoms/buttons/buttons.module.scss | 15 +++++-- .../molecules/buttons/back-to-top.module.scss | 49 ++++++++++++++++++++++ .../molecules/buttons/back-to-top.stories.tsx | 41 ++++++++++++++++++ .../molecules/buttons/back-to-top.test.tsx | 10 +++++ src/components/molecules/buttons/back-to-top.tsx | 40 ++++++++++++++++++ 9 files changed, 204 insertions(+), 7 deletions(-) create mode 100644 src/components/molecules/buttons/back-to-top.module.scss create mode 100644 src/components/molecules/buttons/back-to-top.stories.tsx create mode 100644 src/components/molecules/buttons/back-to-top.test.tsx create mode 100644 src/components/molecules/buttons/back-to-top.tsx (limited to 'src/components') diff --git a/src/components/atoms/buttons/button-link.stories.tsx b/src/components/atoms/buttons/button-link.stories.tsx index d4df676..6fe786b 100644 --- a/src/components/atoms/buttons/button-link.stories.tsx +++ b/src/components/atoms/buttons/button-link.stories.tsx @@ -43,6 +43,21 @@ export default { required: false, }, }, + shape: { + control: { + type: 'select', + }, + description: 'The link shape.', + options: ['rectangle', 'square'], + table: { + category: 'Options', + defaultValue: { summary: 'rectangle' }, + }, + type: { + name: 'string', + required: false, + }, + }, target: { control: { type: null, diff --git a/src/components/atoms/buttons/button-link.tsx b/src/components/atoms/buttons/button-link.tsx index c33a4b7..47fe4b0 100644 --- a/src/components/atoms/buttons/button-link.tsx +++ b/src/components/atoms/buttons/button-link.tsx @@ -15,6 +15,10 @@ type ButtonLinkProps = { * ButtonLink kind. Default: secondary. */ kind?: 'primary' | 'secondary'; + /** + * ButtonLink shape. Default: rectangle. + */ + shape?: 'rectangle' | 'square'; /** * Define an URL as target. */ @@ -30,18 +34,26 @@ const ButtonLink: FC = ({ children, target, kind = 'secondary', + shape = 'rectangle', external = false, ...props }) => { const kindClass = styles[`btn--${kind}`]; + const shapeClass = styles[`btn--${shape}`]; return external ? ( - + {children} ) : ( - - {children} + + + {children} + ); }; diff --git a/src/components/atoms/buttons/button.stories.tsx b/src/components/atoms/buttons/button.stories.tsx index 5af61bd..bec5e5d 100644 --- a/src/components/atoms/buttons/button.stories.tsx +++ b/src/components/atoms/buttons/button.stories.tsx @@ -75,6 +75,21 @@ export default { required: false, }, }, + shape: { + control: { + type: 'select', + }, + description: 'The link shape.', + options: ['rectangle', 'square'], + table: { + category: 'Options', + defaultValue: { summary: 'rectangle' }, + }, + type: { + name: 'string', + required: false, + }, + }, type: { control: { type: 'select', diff --git a/src/components/atoms/buttons/button.tsx b/src/components/atoms/buttons/button.tsx index 420ee74..08b8d67 100644 --- a/src/components/atoms/buttons/button.tsx +++ b/src/components/atoms/buttons/button.tsx @@ -18,6 +18,10 @@ export type ButtonProps = { * A callback function to handle click. */ onClick?: MouseEventHandler; + /** + * Button shape. Default: rectangle. + */ + shape?: 'rectangle' | 'square'; /** * Button type attribute. Default: button. */ @@ -33,16 +37,18 @@ const Button: FC = ({ children, disabled = false, kind = 'secondary', + shape = 'rectangle', type = 'button', ...props }) => { const kindClass = styles[`btn--${kind}`]; + const shapeClass = styles[`btn--${shape}`]; return (