Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modals from Tobira #5

Merged
merged 19 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
"prepare": "npm run build"
},
"devDependencies": {
"@opencast/eslint-config-ts-react": "^0.1.0",
"@opencast/eslint-config-ts-react": "^0.2.0",
"@types/react": "^18.2.13",
"@types/react-dom": "^18.2.19",
LukasKalbertodt marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "^5.1.3"
},
"peerDependencies": {
"@emotion/react": "^11.11.1",
"@emotion/react": "^11.11.4",
"@floating-ui/react": "^0.24.3",
"focus-trap-react": "^10.2.3",
"react": "^18.2.0",
"react-icons": "^4.9.0",
"react-merge-refs": "^2.0.2"
Expand Down
90 changes: 90 additions & 0 deletions src/button.tsx
Arnei marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from "react";
import { Interpolation, Theme } from "@emotion/react";
import { AppkitConfig, focusStyle, match, useAppkitConfig } from ".";

/**
* A mostly unstyled button used to build buttons. Always use this instead of
Expand All @@ -20,3 +22,91 @@ export const ProtoButton = React.forwardRef<HTMLButtonElement, JSX.IntrinsicElem
{...rest}
>{children}</button>,
);

/** The kind of buttons a "Button" can be. Used for styling */
export type Kind = "normal" | "danger" | "call-to-action";

type ButtonProps = JSX.IntrinsicElements["button"] & {
kind?: Kind;
extraCss?: Interpolation<Theme>;
};

/** A styled button */
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ kind = "normal", extraCss, children, ...rest }, ref) => {
const config = useAppkitConfig();

return (
<button ref={ref} type="button" css={css(config, kind, extraCss)} {...rest}>{children}</button>
);
},
);

/**
* Returns css for different types of buttons.
* Comes in the kinds "normal", "danger" and "happy".
Arnei marked this conversation as resolved.
Show resolved Hide resolved
*/
const css = (
config: AppkitConfig,
kind: Kind,
extraCss: Interpolation<Theme> = {}
): Interpolation<Theme> => {
const notDisabledStyle = match(kind, {
"normal": () => ({
border: `1px solid ${config.colors.neutral40}`,
color: config.colors.neutral90,
"&:hover, &:focus-visible": {
border: `1px solid ${config.colors.neutral60}`,
backgroundColor: config.colors.neutral15,
},
}),

"danger": () => ({
border: `1px solid ${config.colors.danger4}`,
color: config.colors.danger4,
"&:hover, &:focus-visible": {
border: `1px solid ${config.colors.danger5}`,
backgroundColor: config.colors.danger4,
color: config.colors.danger0BwInverted, // danger0BwInverted
Arnei marked this conversation as resolved.
Show resolved Hide resolved
},
}),

"call-to-action": () => ({
border: `1px solid ${config.colors.happy5}`,
color: config.colors.happy4BwInverted, // happy0BwInverted
backgroundColor: config.colors.happy4,
"&:hover, &:focus-visible": {
border: `1px solid ${config.colors.happy6}`,
backgroundColor: config.colors.happy5,
color: config.colors.happy5BwInverted, // happy1BwInverted
Arnei marked this conversation as resolved.
Show resolved Hide resolved
},
}),
});

return {
borderRadius: 8,
display: "inline-flex",
alignItems: "center",
padding: "7px 14px",
gap: 12,
whiteSpace: "nowrap",
backgroundColor: config.colors.neutral10,
transition: "background-color 0.15s, border-color 0.15s",
textDecoration: "none",
"& > svg": {
fontSize: 20,
},
"&:disabled": {
border: `1px solid ${config.colors.neutral25}`,
color: config.colors.neutral40,
},
"&:not([disabled])": {
cursor: "pointer",
...notDisabledStyle,
...focusStyle(config, { offset: -1 }),
},
...extraCss as Record<string, unknown>,
};
};

export const buttonStyle = css;
47 changes: 47 additions & 0 deletions src/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { LuAlertTriangle, LuInfo } from "react-icons/lu";
import { match, useAppkitConfig } from ".";


type Props = JSX.IntrinsicElements["div"] & {
kind: "error" | "info";
iconPos?: "left" | "top";
};

/** A styled container for different purposes */
export const Card: React.FC<Props> = ({ kind, iconPos = "left", children, ...rest }) => {
const config = useAppkitConfig();

return (
<div
css={{
display: "inline-flex",
flexDirection: iconPos === "left" ? "row" : "column",
borderRadius: 4,
padding: "8px 16px",
gap: 16,
alignItems: "center",
"& > svg": {
fontSize: 24,
minWidth: 24,
},
...match(kind, {
"error": () => ({
backgroundColor: config.colors.danger0,
border: `1.5px solid ${config.colors.danger0}`,
color: config.colors.danger0BwInverted,
}) as Record<string, string>,
"info": () => ({
backgroundColor: config.colors.neutral10,
}),
}),
}}
{...rest}
>
{match(kind, {
"error": () => <LuAlertTriangle />,
"info": () => <LuInfo css={{ color: config.colors.neutral60 }} />,
})}
<div>{children}</div>
</div>
);
};
20 changes: 20 additions & 0 deletions src/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ html[data-color-scheme="light"], html:not([data-color-scheme]) {
--color-neutral90: #181818;

--color-danger0: #feedeb;
--color-danger0-bw-inverted: #fff;
--color-danger1: #ffd2cd;
--color-danger1-bw-inverted: #fff;
Arnei marked this conversation as resolved.
Show resolved Hide resolved
--color-danger2: #feaba1;
--color-danger4: #c22a2c;
--color-danger5: #880e11;
Expand All @@ -23,8 +25,11 @@ html[data-color-scheme="light"], html:not([data-color-scheme]) {
--color-accent8: #215D99;
--color-accent7: #3073B8;
--color-accent6: #3E8AD8;
--color-accent6-bw-inverted: #000;
--color-accent5: #4DA1F7;
--color-accent5-bw-inverted: #000;
--color-accent4: #71B4F9;
--color-accent4-bw-inverted: #000;

--color-focus: #215D99;
color-scheme: light;
Expand All @@ -46,7 +51,9 @@ html[data-color-scheme="dark"] {
--color-neutral90: #c4c4c4;

--color-danger0: #361314;
--color-danger0-bw-inverted: #fff;
--color-danger1: #462522;
--color-danger1-bw-inverted: #fff;
--color-danger2: #712f2a;
--color-danger4: #e0584d;
--color-danger5: #fb7c67;
Expand All @@ -55,8 +62,11 @@ html[data-color-scheme="dark"] {
--color-accent8: #7da4db;
--color-accent7: #588ccd;
--color-accent6: #1f72ba;
--color-accent6-bw-inverted: #fff;
--color-accent5: #1c619e;
--color-accent5-bw-inverted: #fff;
--color-accent4: #195483;
--color-accent4-bw-inverted: #fff;

--color-focus: #B8D9FC;
color-scheme: dark;
Expand All @@ -78,16 +88,21 @@ html[data-color-scheme="light-high-contrast"] {
--color-neutral90: #000;

--color-danger0: #fff;
--color-danger0-bw-inverted: #fff;
--color-danger1: #fff;
--color-danger1-bw-inverted: #fff;
Arnei marked this conversation as resolved.
Show resolved Hide resolved
--color-danger2: #a50613;
--color-danger4: #a50613;
--color-danger5: #a50613;

--color-accent8: #000099;
--color-accent7: #000099;
--color-accent6: #000099;
--color-accent6-bw-inverted: #fff;
--color-accent5: #000099;
--color-accent5-bw-inverted: #fff;
--color-accent4: #000099;
--color-accent4-bw-inverted: #fff;

--color-focus: #000099;
color-scheme: light;
Expand All @@ -109,16 +124,21 @@ html[data-color-scheme="dark-high-contrast"] {
--color-neutral90: #fff;

--color-danger0: #000;
--color-danger0-bw-iInverted: #fff;
Arnei marked this conversation as resolved.
Show resolved Hide resolved
--color-danger1: #000;
--color-danger1-bw-inverted: #fff;
--color-danger2: #eb1722;
--color-danger4: #eb1722;
--color-danger5: #eb1722;

--color-accent8: #a6ffea;
--color-accent7: #a6ffea;
--color-accent6: #a6ffea;
--color-accent6-bw-inverted: #000;
--color-accent5: #a6ffea;
--color-accent5-bw-inverted: #000;
--color-accent4: #a6ffea;
--color-accent4-bw-inverted: #000;

--color-focus: #a6ffea;
color-scheme: dark;
Expand Down
28 changes: 28 additions & 0 deletions src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,30 @@ export type ColorConfig = {
neutral90: string,

danger0: string,
danger0BwInverted: string,
danger1: string,
danger1BwInverted: string,
danger2: string,
danger4: string,
danger5: string,

happy4: string;
happy4BwInverted: string;
happy5: string;
happy5BwInverted: string;
happy6: string;
happy6BwInverted: string;
happy7: string;
happy8: string;

accent8: string;
accent7: string;
accent6: string;
accent6BwInverted: string;
accent5: string;
accent5BwInverted: string;
accent4: string;
accent4BwInverted: string;

focus: string;
};
Expand All @@ -59,16 +73,30 @@ export const DEFAULT_CONFIG: AppkitConfig = {
neutral90: "var(--color-neutral90)",

danger0: "var(--color-danger0)",
danger0BwInverted: "var(--color-danger0-bw-inverted)",
danger1: "var(--color-danger1)",
danger1BwInverted: "var(--color-danger1-bw-inverted)",
danger2: "var(--color-danger2)",
danger4: "var(--color-danger4)",
danger5: "var(--color-danger5)",

happy4: "var(--color-accent4)",
happy4BwInverted: "var(--color-accent4-bw-inverted)",
happy5: "var(--color-accent5)",
happy5BwInverted: "var(--color-accent5-bw-inverted)",
happy6: "var(--color-accent6)",
happy6BwInverted: "var(--color-accent6-bw-inverted)",
happy7: "var(--color-accent7)",
happy8: "var(--color-accent8)",

accent8: "var(--color-accent8)",
accent7: "var(--color-accent7)",
accent6: "var(--color-accent6)",
accent6BwInverted: "var(--color-accent6-bw-inverted)",
accent5: "var(--color-accent5)",
accent5BwInverted: "var(--color-accent5-bw-inverted)",
accent4: "var(--color-accent4)",
accent4BwInverted: "var(--color-accent4-bw-inverted)",

focus: "var(--color-accent8)",
},
Expand Down
Loading
Loading