Skip to content

Commit

Permalink
refactor(actions): improve actions code
Browse files Browse the repository at this point in the history
fix #191
  • Loading branch information
morewings committed Jun 14, 2024
1 parent df9fe92 commit 4723c23
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 75 deletions.
2 changes: 2 additions & 0 deletions src/internal/Actions/ActionButton.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import url("@/lib/Layout/customMedia.css");

.row {
display: flex;
flex-direction: column;
Expand Down
10 changes: 7 additions & 3 deletions src/internal/Actions/Actions.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
max-width: 240px;

& .action-row {
&:first-of-type {
& .primary-action,
& .inverted-action {
& .primary-action,
& .inverted-action {
&:first-of-type {
border-top: none;
}

&:not(:only-child, :last-child) {
border-right: var(--fg-border-width-100) solid var(--fg-background-100);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/internal/Actions/mockActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import {fn} from '@storybook/test';

import {CloudUpload, IconFile} from '@/internal/Icons';
import type {Props as ActionProps} from '@/internal/Actions/ActionButton.tsx';

import type {Props as ActionProps} from './ActionButton.tsx';

export const actionsMockMultiple = [
{title: 'Default Action', onClick: fn()},
Expand Down
28 changes: 7 additions & 21 deletions src/lib/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {DataAttributes, LibraryProps} from '@/internal/LibraryAPI';
import {useInternalId} from '@/internal/hooks/useInternalId.ts';
import {useLinkRefs} from '@/internal/hooks/useLinkRefs.ts';
import {Picture} from '@/lib';
import {ActionButton} from '@/internal/Actions';
import type {ActionButton} from '@/internal/Actions';
import {ActionsTree} from '@/internal/Actions';

import classes from './Card.module.css';

Expand Down Expand Up @@ -72,26 +73,11 @@ export const Card = forwardRef<HTMLDivElement, Props>(
{headerImageUrl && <Picture className={classes.headerImage} src={headerImageUrl} />}
<div className={classes.body}>{children}</div>
<footer className={classes.actions}>
{actions.map((actionSlot, i) => {
if (Array.isArray(actionSlot)) {
const [left, right] = actionSlot;
return (
<div key={`${id}-${i}`} className={classes.row}>
<ActionButton {...left} className={classes.actionButton} />
<ActionButton {...right} className={classes.actionButton} />
</div>
);
} else {
return (
<div key={`${id}-${i}`} className={classes.row}>
<ActionButton
{...actionSlot}
className={classes.actionButton}
/>
</div>
);
}
})}
<ActionsTree
actions={actions}
classNameAction={classes.actionButton}
classNameRow={classes.row}
/>
</footer>
</LocalRoot>
);
Expand Down
4 changes: 0 additions & 4 deletions src/lib/Dialog/Dialog.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,4 @@
display: flex;
flex-direction: column;
width: 100%;

@media (--viewport-md) {
flex-direction: row;
}
}
20 changes: 2 additions & 18 deletions src/lib/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {useInternalRef} from '@/internal/hooks/useInternalRef.ts';
import {IconClose} from '@/internal/Icons';
import {H3} from '@/lib';
import {useFocusTrap} from '@/internal/hooks/useFocusTrap.ts';
import {ActionButton} from '@/internal/Actions';
import {ActionButton, ActionsTree} from '@/internal/Actions';

import {TransitionDialog} from './TransitionDialog.tsx';
import {useDialogState} from './useDialogState.tsx';
Expand Down Expand Up @@ -115,23 +115,7 @@ export const Dialog = forwardRef<HTMLDialogElement, Props>(
)}
<div className={classNames(classes.body, className)}>{children}</div>
<footer className={classes.actions}>
{actions.map((actionSlot, i) => {
if (Array.isArray(actionSlot)) {
const [left, right] = actionSlot;
return (
<div key={`${id}-${i}`} className={classes.row}>
<ActionButton {...left} />
<ActionButton {...right} />
</div>
);
} else {
return (
<div key={`${id}-${i}`} className={classes.row}>
<ActionButton {...actionSlot} />
</div>
);
}
})}
<ActionsTree actions={actions} />
{showCloseButton && (
<div key={`${id}-close`} className={classes.row}>
<ActionButton
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Toast/Toast.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
width: 100%;
}

.toast .action-button {
.action-button {
--icon-size: calc(var(--fg-size-unit) * 3);

font-size: var(--fg-font-size-small);
Expand Down
32 changes: 5 additions & 27 deletions src/lib/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {useInterval} from '@/internal/hooks/useInterval.ts';
import {useInternalRef} from '@/internal/hooks/useInternalRef.ts';
import {TransitionSlideBottom} from '@/internal/Transitions';
import type {ActionProps} from '@/internal/Actions';
import {ActionButton} from '@/internal/Actions';
import {ActionsTree, ActionButton} from '@/internal/Actions';

import {useToastState} from './useToastState.tsx';
import classes from './Toast.module.css';
Expand Down Expand Up @@ -110,32 +110,10 @@ export const Toast = forwardRef<HTMLDivElement, Props>(
</div>
</div>
<footer className={classes.actions}>
{actions.map((actionSlot, i) => {
if (Array.isArray(actionSlot)) {
const [left, right] = actionSlot;
return (
<div key={`${id}-${i}`} className={classes.row}>
<ActionButton
{...left}
className={classes.actionButton}
/>
<ActionButton
{...right}
className={classes.actionButton}
/>
</div>
);
} else {
return (
<div key={`${id}-${i}`} className={classes.row}>
<ActionButton
{...actionSlot}
className={classes.actionButton}
/>
</div>
);
}
})}
<ActionsTree
actions={actions}
classNameAction={classes.actionButton}
/>
<div key={`${id}-close`} className={classes.row}>
<ActionButton
className={classes.actionButton}
Expand Down

0 comments on commit 4723c23

Please sign in to comment.