aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/buttons
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-06 17:48:03 +0200
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:14:41 +0100
commit12a03a9a72f7895d571dbaeeb245d92aa277a610 (patch)
tree41b6b07928e4f5e101b7ea5d8389bb4325bbac76 /src/components/molecules/buttons
parentfb860884857da73ee5b5e897745301cdf1d770a2 (diff)
refactor(components): merge HeadingButton and Widget components
The HeadingButton component was only used inside Widget component and it is not very useful on its own so I merge the two components in a new Collapsible component.
Diffstat (limited to 'src/components/molecules/buttons')
-rw-r--r--src/components/molecules/buttons/heading-button.module.scss44
-rw-r--r--src/components/molecules/buttons/heading-button.stories.tsx104
-rw-r--r--src/components/molecules/buttons/heading-button.test.tsx33
-rw-r--r--src/components/molecules/buttons/heading-button.tsx67
-rw-r--r--src/components/molecules/buttons/index.ts1
5 files changed, 0 insertions, 249 deletions
diff --git a/src/components/molecules/buttons/heading-button.module.scss b/src/components/molecules/buttons/heading-button.module.scss
deleted file mode 100644
index 689f1e6..0000000
--- a/src/components/molecules/buttons/heading-button.module.scss
+++ /dev/null
@@ -1,44 +0,0 @@
-@use "../../../styles/abstracts/functions" as fun;
-
-.icon {
- transition: all 0.25s ease-in-out 0s;
-}
-
-.wrapper {
- display: flex;
- flex-flow: row nowrap;
- align-items: center;
- justify-content: space-between;
- gap: var(--spacing-md);
- width: 100%;
- padding: 0 var(--spacing-2xs);
- position: sticky;
- top: 0;
- background: inherit;
- border: none;
- border-top: fun.convert-px(2) solid var(--color-primary-dark);
- border-bottom: fun.convert-px(2) solid var(--color-primary-dark);
- cursor: pointer;
-
- .heading {
- padding: var(--spacing-2xs) 0;
- background: none;
- font-size: var(--font-size-xl);
- font-weight: 500;
- text-align: left;
- }
-
- &:hover,
- &:focus {
- .icon {
- background: var(--color-primary-light);
- color: var(--color-fg-inverted);
- transform: scale(1.25);
-
- &::before,
- &::after {
- background: var(--color-bg);
- }
- }
- }
-}
diff --git a/src/components/molecules/buttons/heading-button.stories.tsx b/src/components/molecules/buttons/heading-button.stories.tsx
deleted file mode 100644
index 9beda2b..0000000
--- a/src/components/molecules/buttons/heading-button.stories.tsx
+++ /dev/null
@@ -1,104 +0,0 @@
-import { ComponentMeta, ComponentStory } from '@storybook/react';
-import { useState } from 'react';
-import { HeadingButton as HeadingButtonComponent } from './heading-button';
-
-/**
- * HeadingButton - Storybook Meta
- */
-export default {
- title: 'Molecules/Buttons/HeadingButton',
- component: HeadingButtonComponent,
- argTypes: {
- className: {
- control: {
- type: 'text',
- },
- description: 'Set additional classnames to the button.',
- table: {
- category: 'Styles',
- },
- type: {
- name: 'string',
- required: false,
- },
- },
- expanded: {
- control: {
- type: null,
- },
- description: 'Heading button state (plus or minus).',
- type: {
- name: 'boolean',
- required: true,
- },
- },
- level: {
- control: {
- type: 'number',
- min: 1,
- max: 6,
- },
- description: 'Heading level.',
- type: {
- name: 'number',
- required: true,
- },
- },
- setExpanded: {
- control: {
- type: null,
- },
- description: 'Callback function to set heading button state.',
- type: {
- name: 'function',
- required: true,
- },
- },
- title: {
- control: {
- type: 'text',
- },
- description: 'Heading title.',
- type: {
- name: 'string',
- required: true,
- },
- },
- },
-} as ComponentMeta<typeof HeadingButtonComponent>;
-
-const Template: ComponentStory<typeof HeadingButtonComponent> = ({
- expanded,
- setExpanded: _setExpanded,
- ...args
-}) => {
- const [isExpanded, setIsExpanded] = useState<boolean>(expanded);
-
- return (
- <HeadingButtonComponent
- expanded={isExpanded}
- setExpanded={setIsExpanded}
- {...args}
- />
- );
-};
-
-/**
- * Heading Button Stories - Expanded
- */
-export const Expanded = Template.bind({});
-Expanded.args = {
- expanded: true,
- level: 2,
- title: 'Your title',
-};
-
-/**
- * Heading Button Stories - Collapsed
- */
-export const Collapsed = Template.bind({});
-Collapsed.args = {
- expanded: false,
- level: 2,
- title: 'Your title',
-};
diff --git a/src/components/molecules/buttons/heading-button.test.tsx b/src/components/molecules/buttons/heading-button.test.tsx
deleted file mode 100644
index 4d3d91e..0000000
--- a/src/components/molecules/buttons/heading-button.test.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import { describe, expect, it } from '@jest/globals';
-import { render, screen } from '../../../../tests/utils';
-import { HeadingButton } from './heading-button';
-
-describe('HeadingButton', () => {
- it('renders a button to collapse.', () => {
- render(
- <HeadingButton
- level={2}
- title="The accordion title"
- expanded={true}
- setExpanded={() => null}
- />
- );
- expect(
- screen.getByRole('button', { name: 'Collapse The accordion title' })
- ).toBeInTheDocument();
- });
-
- it('renders a button to expand.', () => {
- render(
- <HeadingButton
- level={2}
- title="The accordion title"
- expanded={false}
- setExpanded={() => null}
- />
- );
- expect(
- screen.getByRole('button', { name: 'Expand The accordion title' })
- ).toBeInTheDocument();
- });
-});
diff --git a/src/components/molecules/buttons/heading-button.tsx b/src/components/molecules/buttons/heading-button.tsx
deleted file mode 100644
index 3c3eef5..0000000
--- a/src/components/molecules/buttons/heading-button.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import { useCallback, type FC, type SetStateAction } from 'react';
-import { useIntl } from 'react-intl';
-import { Heading, type HeadingProps, Icon } from '../../atoms';
-import styles from './heading-button.module.scss';
-
-export type HeadingButtonProps = Pick<HeadingProps, 'level'> & {
- /**
- * Set additional classnames to the button.
- */
- className?: string;
- /**
- * Accordion state.
- */
- expanded: boolean;
- /**
- * Callback function to set accordion state on click.
- */
- setExpanded: (value: SetStateAction<boolean>) => void;
- /**
- * Accordion title.
- */
- title: string;
-};
-
-/**
- * HeadingButton component
- *
- * Render a button as accordion title to toggle body.
- */
-export const HeadingButton: FC<HeadingButtonProps> = ({
- className = '',
- expanded,
- level,
- setExpanded,
- title,
-}) => {
- const intl = useIntl();
- const btnClass = `${styles.wrapper} ${className}`;
- const iconState = expanded ? 'minus' : 'plus';
- const titlePrefix = expanded
- ? intl.formatMessage({
- defaultMessage: 'Collapse',
- description: 'HeadingButton: title prefix (expanded state)',
- id: 'UX9Bu8',
- })
- : intl.formatMessage({
- defaultMessage: 'Expand',
- description: 'HeadingButton: title prefix (collapsed state)',
- id: 'bcyOgC',
- });
-
- const toggleExpand = useCallback(
- () => setExpanded((prev) => !prev),
- [setExpanded]
- );
-
- return (
- <button className={btnClass} onClick={toggleExpand} type="button">
- <Heading className={styles.heading} level={level}>
- {/* eslint-disable-next-line react/jsx-no-literals -- SR class allowed */}
- <span className="screen-reader-text">{titlePrefix} </span>
- {title}
- </Heading>
- <Icon className={styles.icon} shape={iconState} />
- </button>
- );
-};
diff --git a/src/components/molecules/buttons/index.ts b/src/components/molecules/buttons/index.ts
index e0a10c1..b2930aa 100644
--- a/src/components/molecules/buttons/index.ts
+++ b/src/components/molecules/buttons/index.ts
@@ -1,3 +1,2 @@
export * from './back-to-top';
-export * from './heading-button';
export * from './help-button';