@indietabletop/appkit 3.2.0-11 → 3.2.0-13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ import {
2
+ DialogProvider,
3
+ useDialogContext,
4
+ useStoreState,
5
+ } from "@ariakit/react";
6
+ import type { ReactElement, ReactNode } from "react";
7
+
8
+ function DialogGuard(props: { children: ReactNode }) {
9
+ const dialog = useDialogContext();
10
+ const isMounted = useStoreState(dialog, (store) => store?.mounted);
11
+ if (!isMounted) {
12
+ return null;
13
+ }
14
+ return props.children;
15
+ }
16
+
17
+ /**
18
+ * Wraps AriaKit's DialogProvider, but take a tuple of Dialog a DialogDisclosure
19
+ * elements as children, and makes sense that the Dialog component is not
20
+ * rendered when it is hidden.
21
+ *
22
+ * This is important in cases where the dialog contains a form that should only
23
+ * be initialized and re-initialized when the dialog opens, not when it is first
24
+ * rendered.
25
+ */
26
+ export function DialogTrigger(props: {
27
+ children: [ReactElement, ReactElement];
28
+ }) {
29
+ const [dialog, button] = props.children;
30
+ return (
31
+ <DialogProvider>
32
+ <DialogGuard>{dialog}</DialogGuard>
33
+ {button}
34
+ </DialogProvider>
35
+ );
36
+ }
@@ -2,7 +2,7 @@ import { createTheme, style } from "@vanilla-extract/css";
2
2
  import { recipe } from "@vanilla-extract/recipes";
3
3
  import { textVariants } from "../atomic.css.ts";
4
4
  import { manofa, minion } from "../common.css.ts";
5
- import { Hover } from "../media.ts";
5
+ import { Hover, MinWidth } from "../media.ts";
6
6
 
7
7
  const align = {
8
8
  start: textVariants({ textAlign: "start" }),
@@ -11,7 +11,7 @@ const align = {
11
11
  };
12
12
 
13
13
  export const [letterheadTheme, { padding, footerMargin }] = createTheme({
14
- padding: "clamp(1rem, 8vw, 4rem)",
14
+ padding: "1.25rem",
15
15
  footerMargin: "3rem",
16
16
  });
17
17
 
@@ -25,6 +25,14 @@ export const letterhead = recipe({
25
25
  borderRadius: "1rem",
26
26
  marginInline: "auto",
27
27
  maxInlineSize: "36rem",
28
+
29
+ "@media": {
30
+ [MinWidth.SMALL]: {
31
+ vars: {
32
+ [padding]: `clamp(1.5rem, 8%, 4rem)`,
33
+ },
34
+ },
35
+ },
28
36
  },
29
37
  ],
30
38
 
@@ -0,0 +1,25 @@
1
+ import { Dialog, type DialogProps } from "@ariakit/react";
2
+ import type { ReactNode } from "react";
3
+ import { cx } from "../class-names.ts";
4
+ import * as css from "./style.css.ts";
5
+
6
+ export type ModalDialogProps = Omit<DialogProps, "modal" | "backdrop"> & {
7
+ children: ReactNode;
8
+ variant: "form" | "confirm";
9
+ backdropClassName?: string;
10
+ };
11
+
12
+ export function ModalDialog(props: ModalDialogProps) {
13
+ const { variant, backdropClassName, className, ...dialogProps } = props;
14
+
15
+ return (
16
+ <Dialog
17
+ {...dialogProps}
18
+ {...cx(className, css.dialog({ variant }))}
19
+ backdrop={<div {...cx(css.backdrop, backdropClassName)} />}
20
+ modal
21
+ >
22
+ {props.children}
23
+ </Dialog>
24
+ );
25
+ }
@@ -0,0 +1,87 @@
1
+ import { style, type ComplexStyleRule } from "@vanilla-extract/css";
2
+ import { recipe } from "@vanilla-extract/recipes";
3
+ import { MinWidth } from "../media.ts";
4
+
5
+ const scaleTransition: ComplexStyleRule = {
6
+ transition: "transform 200ms, opacity 200ms",
7
+ transform: "scale(1.1)",
8
+
9
+ selectors: {
10
+ "&[data-enter]": {
11
+ opacity: 1,
12
+ transform: "scale(1)",
13
+ },
14
+
15
+ "&[data-leave]": {
16
+ opacity: 0,
17
+ transform: "scale(0.9)",
18
+ },
19
+ },
20
+ };
21
+
22
+ const translateTransition: ComplexStyleRule = {
23
+ transition: "transform 200ms, opacity 200ms",
24
+ transform: "translateY(5rem)",
25
+
26
+ selectors: {
27
+ "&[data-enter]": {
28
+ opacity: 1,
29
+ transform: "translateY(0)",
30
+ },
31
+
32
+ "&[data-leave]": {
33
+ opacity: 0,
34
+ transform: "translateY(5rem)",
35
+ },
36
+ },
37
+ };
38
+
39
+ export const dialog = recipe({
40
+ base: {
41
+ position: "fixed",
42
+ inset: 0,
43
+ zIndex: 100,
44
+ margin: "auto",
45
+ overflow: "auto",
46
+ opacity: 0,
47
+ backgroundColor: "white",
48
+ },
49
+
50
+ variants: {
51
+ variant: {
52
+ form: {
53
+ ...translateTransition,
54
+ inlineSize: "100%",
55
+ blockSize: "100%",
56
+
57
+ "@media": {
58
+ [MinWidth.MEDIUM]: {
59
+ ...scaleTransition,
60
+ blockSize: "fit-content",
61
+ maxInlineSize: "40rem",
62
+ maxBlockSize: "90%",
63
+ borderRadius: "1rem",
64
+ },
65
+ },
66
+ },
67
+
68
+ confirm: {
69
+ ...scaleTransition,
70
+ inlineSize: "min(24rem, 90svw)",
71
+ blockSize: "fit-content",
72
+ borderRadius: "1rem",
73
+ },
74
+ },
75
+ },
76
+ });
77
+
78
+ export const backdrop = style({
79
+ backgroundColor: "black",
80
+ opacity: 0,
81
+ transition: "opacity 200ms",
82
+ selectors: {
83
+ "&[data-enter]": {
84
+ opacity: 0.4,
85
+ },
86
+ },
87
+ });
@@ -40,41 +40,52 @@ export type FetchFailureAction =
40
40
  label: string;
41
41
  };
42
42
 
43
- export type FetchFailure = {
43
+ export type FetchFailureMessages = {
44
44
  title: string;
45
45
  description: string;
46
46
  action: FetchFailureAction;
47
47
  };
48
48
 
49
- export const getFetchFailureMessages = createFailureMessageGetter<FetchFailure>(
50
- {
51
- 404: {
52
- title: `Not found`,
53
- description: `The link you have followed might be broken.`,
54
- action: { type: "LINK", href: "~/", label: "Go back" },
55
- },
56
- 500: {
57
- title: `Ooops, something went wrong`,
58
- description: `This is probably an issue with our servers. You can try refreshing.`,
59
- action: { type: "RELOAD", label: "Reload app" },
60
- },
61
- connection: {
62
- title: `No connection`,
63
- description: `Check your interent connection and try again.`,
64
- action: { type: "REFETCH", label: "Retry request" },
49
+ export const getFetchFailureMessages =
50
+ createFailureMessageGetter<FetchFailureMessages>(
51
+ {
52
+ 401: {
53
+ title: "Not logged in",
54
+ description: "You must be logged in to view this page.",
55
+ action: { type: "LINK", href: "~/login", label: "Go to login" },
56
+ },
57
+ 403: {
58
+ title: "Not authorized",
59
+ description: "You might be logged into the wrong account.",
60
+ action: { type: "LINK", href: "~/login", label: "Go to login" },
61
+ },
62
+ 404: {
63
+ title: `Not found`,
64
+ description: `The link you have followed might be broken.`,
65
+ action: { type: "LINK", href: "~/", label: "Go back" },
66
+ },
67
+ 500: {
68
+ title: `Ooops, something went wrong`,
69
+ description: `This is probably an issue with our servers. You can try refreshing.`,
70
+ action: { type: "RELOAD", label: "Reload app" },
71
+ },
72
+ connection: {
73
+ title: `No connection`,
74
+ description: `Check your interent connection and try again.`,
75
+ action: { type: "REFETCH", label: "Retry request" },
76
+ },
77
+ fallback: {
78
+ title: `Ooops, something went wrong`,
79
+ description: `This is probably an issue on our side. You can try refreshing.`,
80
+ action: { type: "RELOAD", label: "Reload app" },
81
+ },
65
82
  },
66
- fallback: {
67
- title: `Ooops, something went wrong`,
68
- description: `This is probably an issue on our side. You can try refreshing.`,
69
- action: { type: "RELOAD", label: "Reload app" },
83
+ {
84
+ onOverride(fallback, override) {
85
+ return { ...fallback, ...override };
86
+ },
70
87
  },
71
- },
72
- {
73
- onOverride(fallback, override) {
74
- return { ...fallback, ...override };
75
- },
76
- },
77
- );
88
+ );
78
89
 
79
90
  export const getSubmitFailureMessage = createFailureMessageGetter(
80
91
  {
package/lib/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  // Components
2
+ export * from "./DialogTrigger/index.tsx";
2
3
  export * from "./ExternalLink.tsx";
3
4
  export * from "./FormSubmitButton.tsx";
4
5
  export * from "./FullscreenDismissBlocker.tsx";
@@ -6,6 +7,7 @@ export * from "./IndieTabletopClubSymbol.tsx";
6
7
  export * from "./Letterhead/index.tsx";
7
8
  export * from "./LetterheadForm/index.tsx";
8
9
  export * from "./LoadingIndicator.tsx";
10
+ export * from "./ModalDialog/index.tsx";
9
11
  export * from "./ServiceWorkerHandler.tsx";
10
12
 
11
13
  // Hooks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indietabletop/appkit",
3
- "version": "3.2.0-11",
3
+ "version": "3.2.0-13",
4
4
  "description": "A collection of modules used in apps built by Indie Tabletop Club",
5
5
  "private": false,
6
6
  "type": "module",