Skip to content

Commit

Permalink
[DEV-11281] Implemented new Accordion component
Browse files Browse the repository at this point in the history
  • Loading branch information
fgyimah committed Aug 10, 2023
1 parent 40176b9 commit 8dabae1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@import "styles/variables";
@import "styles/helpers";

.Accordion {
border-top: 1px solid rgba($color: $white, $alpha: 0.12);
}

.button {
@include btn-unstyled;

display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: $spacing-2;
color: $grey-300;
font-size: $font-size-small;
font-weight: 600;
}

.content {
display: none;
padding: 0 $spacing-2 $spacing-2;

&.open {
display: block;
}
}

.icon {
fill: $white;
transition: transform 0.3s ease-in;

&.open {
transform: rotate(180deg);
}
}
41 changes: 41 additions & 0 deletions packages/slate-editor/src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import classNames from 'classnames';
import React, { useState, type ReactNode } from 'react';

import { Caret } from '#icons';

import styles from './Accordion.module.scss';

interface Props {
title: string;
children: ReactNode;
}

export function Accordion({ title, children }: Props) {
const [isOpen, setIsOpen] = useState(false);

function toggleOpen() {
setIsOpen(!isOpen);
}

return (
<div className={styles.Accordion}>
<button className={styles.button} onClick={toggleOpen}>
<span>{title}</span>
{
<Caret
className={classNames(styles.icon, {
[styles.open]: isOpen,
})}
/>
}
</button>
<div
className={classNames(styles.content, {
[styles.open]: isOpen,
})}
>
{children}
</div>
</div>
);
}
1 change: 1 addition & 0 deletions packages/slate-editor/src/components/Accordion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Accordion } from './Accordion';
1 change: 1 addition & 0 deletions packages/slate-editor/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { Accordion } from './Accordion';
export { Avatar } from './Avatar';
export { CloseButtonV2 } from './CloseButtonV2';
export { CloseButton, EditorBlock, ResizableEditorBlock } from './EditorBlock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import classNames from 'classnames';
import React, { useCallback, useEffect, useState } from 'react';

import {
Accordion,
Button,
Input,
type OptionsGroupOption,
Expand Down Expand Up @@ -166,18 +167,15 @@ export function ButtonMenu({ onUpdate, onClose, onRemove, value, withNewTabOptio
</VStack>
</Toolbox.Section>

<Toolbox.Section>
<Accordion title="Styling options">
<VStack spacing="2">
<VStack spacing="1-5">
<Toolbox.Caption>Styling options</Toolbox.Caption>
<OptionsGroup
name="variant"
onChange={(variant) => onUpdate({ variant })}
options={BUTTON_MENU_VARIANT_OPTIONS}
selectedValue={value.variant}
variant="pills"
/>
</VStack>
<OptionsGroup
name="variant"
onChange={(variant) => onUpdate({ variant })}
options={BUTTON_MENU_VARIANT_OPTIONS}
selectedValue={value.variant}
variant="pills"
/>

<VStack spacing="1-5">
<Toolbox.Caption>Alignment</Toolbox.Caption>
Expand All @@ -189,7 +187,7 @@ export function ButtonMenu({ onUpdate, onClose, onRemove, value, withNewTabOptio
/>
</VStack>
</VStack>
</Toolbox.Section>
</Accordion>

<Toolbox.Footer>
<Button variant="clear" icon={Delete} fullWidth onClick={onRemove}>
Expand Down
3 changes: 3 additions & 0 deletions packages/slate-editor/src/icons/Caret.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/slate-editor/src/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { default as ButtonLayoutLeft } from './ButtonLayoutLeft.svg';
export { default as ButtonLayoutRight } from './ButtonLayoutRight.svg';
export { default as ButtonLayoutCenter } from './ButtonLayoutCenter.svg';
export { default as ButtonLayoutWide } from './ButtonLayoutWide.svg';
export { default as Caret } from './Caret.svg';
export { default as ChickenNoSignalIllustration } from './Chicken-no-signal-Illustration.svg';
export { default as Bookmark } from './Embed.svg'; // this will be reworked in scope of MT-4462
export { default as Clear } from './Clear.svg';
Expand Down

0 comments on commit 8dabae1

Please sign in to comment.