Skip to content

Commit

Permalink
feat(slice-machine): add FieldSet component
Browse files Browse the repository at this point in the history
  • Loading branch information
bapmrl committed Jan 24, 2024
1 parent e45e62d commit 57efa6d
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 0 deletions.
86 changes: 86 additions & 0 deletions packages/slice-machine/src/components/FieldSet/FieldSet.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
.flex {
all: unset;
display: flex;
}

.column {
composes: flex;
flex-direction: column;
}

.root {
composes: column;
border-color: var(--grey6);
border-radius: 6px;
border-style: solid;
border-width: 1px;
box-shadow: var(--box-shadow-1);
overflow-x: hidden;
}

.row {
composes: flex;
align-items: center;
flex-direction: row;
gap: 8px;
padding-inline: 16px;
}

.child {
box-sizing: border-box;
&:not(:last-child) {
border-bottom: inherit;
}
}

.legend {
composes: row child;
background-color: var(--grey2);
height: 48px;
order: 0;
}

.header {
composes: row child;
background-color: var(--grey2);
height: 72px;
order: 1;
}

.content {
composes: column child;
background-color: var(--grey1);
order: 2;
/* stylelint-disable-next-line declaration-property-value-allowed-list -- Take into account the 1 px bottom border. */
padding: 16px 16px calc(16px - 1px) 16px;
}

.list {
composes: column child;
max-height: 256px;
order: 2;
overflow-y: auto;
}

.listItem {
composes: row child;
background-color: var(--grey1);
flex-shrink: 0;
height: 64px;
}

.listItemText {
flex-grow: 1;
}

.footer {
composes: row child;
background-color: var(--grey1);
height: 48px;
order: 3;
padding-right: 8px;
}

.footerText {
flex-grow: 1;
}
144 changes: 144 additions & 0 deletions packages/slice-machine/src/components/FieldSet/FieldSet.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {
Button,
ButtonGroup,
IconButton,
Text,
tokens,
} from "@prismicio/editor-ui";
import type { Meta, StoryObj } from "@storybook/react";

import { BitbucketIcon } from "../../icons/BitbucketIcon";
import { GitHubIcon } from "../../icons/GitHubIcon";
import { GitLabIcon } from "../../icons/GitLabIcon";
import {
FieldSet,
FieldSetContent,
FieldSetFooter,
FieldSetHeader,
FieldSetLegend,
FieldSetList,
FieldSetListItem,
} from "./FieldSet";

type Story = StoryObj<typeof meta>;

const meta = {
component: FieldSet,
argTypes: {
children: { control: { disable: true } },
},
} satisfies Meta<typeof FieldSet>;

export default meta;

export const Default = {
args: {
children: (
<>
<FieldSetLegend />
<FieldSetHeader />
<FieldSetList>
<FieldSetListItem action={<Button color="grey">Action</Button>} />
</FieldSetList>
<FieldSetFooter action={<IconButton icon="openInNew" />} />
</>
),
},
} satisfies Story;

export const WithButtonGroupContent = {
args: {
...Default.args,
children: (
<>
<FieldSetLegend>Connected Git Repository</FieldSetLegend>
<FieldSetContent>
<ButtonGroup color="grey">
<Button
renderStartIcon={() => (
<GitHubIcon color={tokens.color.greyLight11} />
)}
sx={{ flexGrow: 1 }}
>
GitHub
</Button>
<Button
disabled
renderStartIcon={() => (
<BitbucketIcon color={tokens.color.greyLight11} />
)}
sx={{ flexGrow: 1 }}
>
Bitbucket{" "}
<Text color="inherit" variant="small">
(soon)
</Text>
</Button>
<Button
disabled
renderStartIcon={() => (
<GitLabIcon color={tokens.color.greyLight11} />
)}
sx={{ flexGrow: 1 }}
>
GitLab{" "}
<Text color="inherit" variant="small">
(soon)
</Text>
</Button>
</ButtonGroup>
</FieldSetContent>
<FieldSetFooter action={<IconButton icon="openInNew" />}>
Learn more about Prismic for Git
</FieldSetFooter>
</>
),
},
parameters: { controls: { hideNoControlsWarning: true, include: [] } },
} satisfies Story;

export const WithHeaderAndListOverflow = {
args: {
...Default.args,
children: (
<>
<FieldSetLegend>Connected Git Repository</FieldSetLegend>
<FieldSetHeader />
<FieldSetList>
{[...Array(100).keys()].map((index) => (
<FieldSetListItem
action={<Button color="grey">Connect</Button>}
key={index}
>
Repository <Text color="grey11">• xd ago</Text>
</FieldSetListItem>
))}
</FieldSetList>
<FieldSetFooter action={<IconButton icon="openInNew" />}>
Learn more about Prismic for Git
</FieldSetFooter>
</>
),
},
parameters: { controls: { hideNoControlsWarning: true, include: [] } },
};

export const WithSingleListItem = {
args: {
...Default.args,
children: (
<>
<FieldSetLegend>Connected Git Repository</FieldSetLegend>
<FieldSetList>
<FieldSetListItem action={<Button color="grey">Disconnect</Button>}>
Repository <Text color="grey11">• xd ago</Text>
</FieldSetListItem>
</FieldSetList>
<FieldSetFooter action={<IconButton icon="openInNew" />}>
Learn more about Prismic for Git
</FieldSetFooter>
</>
),
},
parameters: { controls: { hideNoControlsWarning: true, include: [] } },
};
72 changes: 72 additions & 0 deletions packages/slice-machine/src/components/FieldSet/FieldSet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Text } from "@prismicio/editor-ui";
import type { FC, PropsWithChildren, ReactNode } from "react";

import styles from "./FieldSet.module.css";

export const FieldSet: FC<PropsWithChildren> = (props) => (
<div {...props} className={styles.root} />
);

export const FieldSetLegend: FC<PropsWithChildren> = ({
children,
...otherProps
}) => (
<div {...otherProps} className={styles.legend}>
<Text color="grey11" component="span" noWrap variant="smallBold">
{children}
</Text>
</div>
);

export const FieldSetHeader: FC<PropsWithChildren> = (props) => (
<div {...props} className={styles.header} />
);

export const FieldSetContent: FC<PropsWithChildren> = (props) => (
<div {...props} className={styles.content} />
);

export const FieldSetList: FC<PropsWithChildren> = (props) => (
<div {...props} className={styles.list} />
);

type FieldSetListItemProps = PropsWithChildren<{ action?: ReactNode }>;

export const FieldSetListItem: FC<FieldSetListItemProps> = ({
action,
children,
...otherProps
}) => (
<div {...otherProps} className={styles.listItem}>
<Text
className={styles.listItemText}
component="span"
noWrap
variant="bold"
>
{children}
</Text>
{action}
</div>
);

type FieldSetFooterProps = PropsWithChildren<{ action?: ReactNode }>;

export const FieldSetFooter: FC<FieldSetFooterProps> = ({
action,
children,
...otherProps
}) => (
<div {...otherProps} className={styles.footer}>
<Text
className={styles.footerText}
color="grey11"
component="span"
noWrap
variant="small"
>
{children}
</Text>
{action}
</div>
);
9 changes: 9 additions & 0 deletions packages/slice-machine/src/components/FieldSet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {
FieldSet,
FieldSetContent,
FieldSetFooter,
FieldSetHeader,
FieldSetLegend,
FieldSetList,
FieldSetListItem,
} from "./FieldSet";
19 changes: 19 additions & 0 deletions packages/slice-machine/src/icons/BitbucketIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { FC, SVGProps } from "react";

export const BitbucketIcon: FC<SVGProps<SVGSVGElement>> = (props) => (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M4.77596 5.47599C4.84147 5.44648 4.91265 5.43167 4.9845 5.4326L19.3525 5.43506C19.4243 5.43413 19.4955 5.44894 19.561 5.47845C19.6265 5.50796 19.6848 5.55146 19.7317 5.60588C19.7786 5.6603 19.8131 5.72433 19.8326 5.79348C19.8521 5.86262 19.8563 5.93521 19.8448 6.00614L19.1802 10.0751H9.71803L10.5722 14.6018H11.1162L11.1162 14.6018H13.7846L14.56 10.0751H19.1803L17.7575 18.8357C17.7387 18.9522 17.6786 19.058 17.5882 19.1339C17.4979 19.2098 17.3832 19.2507 17.2652 19.2492H7.23692C7.2134 19.249 7.19001 19.2476 7.16682 19.2449C7.03392 19.2298 6.90803 19.175 6.80603 19.0868C6.68704 18.9851 6.60772 18.8448 6.58203 18.6904L4.49219 6.00367C4.48069 5.93275 4.48485 5.86016 4.50438 5.79102C4.52392 5.72187 4.55835 5.65784 4.60527 5.60342C4.65218 5.54899 4.71044 5.5055 4.77596 5.47599Z"
fill="currentColor"
/>
</svg>
);
17 changes: 17 additions & 0 deletions packages/slice-machine/src/icons/GitHubIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { FC, SVGProps } from "react";

export const GitHubIcon: FC<SVGProps<SVGSVGElement>> = (props) => (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
d="M12 4C7.57486 4 4 7.57486 4 12C4 15.5246 6.30057 18.5257 9.47429 19.6C9.87429 19.6754 10.0251 19.4251 10.0251 19.2251V17.8754C7.8 18.3497 7.32457 16.8 7.32457 16.8C6.94971 15.8743 6.42514 15.6251 6.42514 15.6251C5.70057 15.1246 6.47543 15.1497 6.47543 15.1497C7.27543 15.2 7.69943 15.9749 7.69943 15.9749C8.42514 17.2 9.57486 16.8503 10.0251 16.6491C10.1006 16.1246 10.2994 15.7749 10.5246 15.5749C8.74971 15.3749 6.87543 14.6754 6.87543 11.6251C6.87543 10.7497 7.17486 10.0503 7.69943 9.47543C7.62514 9.27543 7.34971 8.45029 7.77486 7.34971C7.77486 7.34971 8.44914 7.12457 9.97486 8.17486C10.6266 7.99627 11.2991 7.90405 11.9749 7.90057C12.6491 7.90057 13.3497 8 13.9749 8.17486C15.5006 7.14971 16.1749 7.34971 16.1749 7.34971C16.6 8.45029 16.3246 9.27543 16.2503 9.47543C16.776 10.024 17.0754 10.7497 17.0754 11.624C17.0754 14.6994 15.2 15.3749 13.4251 15.5749C13.6994 15.8251 13.9749 16.2994 13.9749 17.0491V19.2503C13.9749 19.4754 14.1246 19.7246 14.5246 19.6251C17.7006 18.5246 20 15.5246 20 12C20 7.57486 16.4251 4 12 4Z"
fill="currentColor"
/>
</svg>
);
19 changes: 19 additions & 0 deletions packages/slice-machine/src/icons/GitLabIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { FC, SVGProps } from "react";

export const GitLabIcon: FC<SVGProps<SVGSVGElement>> = (props) => (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M14.7881 10.5954L16.5431 5.20756C16.6328 4.93081 17.0594 4.93081 17.1492 5.20756L18.9076 10.5954H14.7881ZM6.6192 5.20756L4.86353 10.5954H8.97968L7.22468 5.20756C7.1349 4.93081 6.70898 4.93081 6.6192 5.20756ZM4.0299 13.2981L4.86352 10.5954H4.86353H8.979H14.7881H18.9076L19.7392 13.2981C19.7796 13.4207 19.7802 13.553 19.7408 13.676C19.7014 13.799 19.624 13.9063 19.5198 13.9826L11.893 19.5257L11.8879 19.5319L11.8923 19.5378L11.8865 19.5336L11.8835 19.5371L11.8852 19.5326L4.24927 13.9826C4.0299 13.8246 3.95092 13.5458 4.0299 13.2981Z"
fill="currentColor"
/>
</svg>
);

0 comments on commit 57efa6d

Please sign in to comment.