Skip to content

Commit

Permalink
CHAKRA IS GONE!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Dec 26, 2023
1 parent c82415e commit 5f7dbd5
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 1,253 deletions.
5 changes: 0 additions & 5 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@
},
"dependencies": {
"@ark-ui/react": "^0.15.0",
"@chakra-ui/next-js": "^2.1.5",
"@chakra-ui/react": "^2.8.0",
"@dnd-kit/core": "^6.0.8",
"@dnd-kit/sortable": "^7.0.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.10.5",
"@heroicons/react": "^2.0.18",
"@hookform/resolvers": "^3.3.1",
"@simplewebauthn/browser": "^8.0.2",
"@uidotdev/usehooks": "^2.4.1",
"colorjs.io": "^0.4.5",
"date-fns": "^2.29.3",
"framer-motion": "^10.16.4",
"lodash": "^4.17.21",
"next": "^14.0.0",
"picmo": "^5.8.5",
Expand Down
15 changes: 8 additions & 7 deletions web/src/app/global.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
@layer reset, base, tokens, recipes, utilities;

@layer base {
*,
*::before,
&::after {
border-color: var(--colors-black-alpha-200);
}
}

:root {
--font-size-h1: 2.488rem;
--font-size-h2: 2.074rem;
Expand Down Expand Up @@ -159,10 +167,3 @@ body {
padding-top: var(--spacing-2);
}
}

/* Chakra makes this impossible to remove so we gotta break out !important... */
*,
*::before,
&::after {
border-color: var(--colors-black-alpha-200) !important;
}
52 changes: 5 additions & 47 deletions web/src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,15 @@
"use client";

import { CacheProvider } from "@chakra-ui/next-js";
import { ChakraProvider, extendTheme } from "@chakra-ui/react";
import { PropsWithChildren } from "react";

import { AuthProvider } from "src/auth/AuthProvider";

// Force chakra to always be light mode - because we're removing it eventually.
type ColourMode = "light" | "dark";
const noopColourModeManager = {
type: "localStorage" as const,
ssr: false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
get(_init?: ColourMode | undefined) {
return "light" as const;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
set(_value: "system") {},
};

export function Providers({ children }: PropsWithChildren) {
return (
<CacheProvider>
<ChakraProvider
theme={extendTheme({
styles: {
// Remove the Chakra defaults - we don't need them with Panda.
// https://chakra-ui.com/docs/styled-system/global-styles#default-styles
global: {
body: {
fontFamily: "unset",
color: "unset",
bg: "unset",
lineHeight: "unset",
},

"*, *::before, &::after": {
borderColor: "unset",
wordWrap: "unset",
},
},
},
})}
// We're not using Chakra's reset, instead we're using Panda CSS.
resetCSS={false}
colorModeManager={noopColourModeManager}
>
<AuthProvider>
{/* -- */}
{children}
{/* -- */}
</AuthProvider>
</ChakraProvider>
</CacheProvider>
<AuthProvider>
{/* -- */}
{children}
{/* -- */}
</AuthProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export function FileDrop({ children, ...props }: PropsWithChildren<Props>) {
onDragOver={(e) => e.preventDefault()}
style={{
backgroundColor: dragging ? "gray.50" : undefined,
outline: dragging
? "2px var(--chakra-colors-red-200) dashed"
: undefined,
outline: dragging ? "2px var(--colors-red-200) dashed" : undefined,
outlineOffset: dragging ? "0.5" : undefined,
}}
>
Expand Down
3 changes: 0 additions & 3 deletions web/src/components/form/ColourInput/ColourInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export function ColourInput(props: Props) {
const { onPointerDown, onPointerUp, hue, ref, angle, value, grabbing } =
useColourInput(props);

// NOTE: we use React's primitive `style` prop here and not "style props" from
// Chakra because this is going to change on every frame while dragging and we
// don't want Emotion.js to generate a whole new stylesheet when these change!
const styles = {
backgroundColor: value,
"--angle": `${angle}deg`,
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/site/Modaldrawer/Modaldrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function ModalDrawer({ children, ...props }: PropsWithChildren<Props>) {
.modaldrawer__overlay {
position: fixed;
inset: 0;
background-color: var(--chakra-colors-blackAlpha-600);
background-color: var(--colors-blackAlpha-600);
z-index: var(--z-index-overlay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HStack, VStack, styled } from "@/styled-system/jsx";

import { Props, useIconEditor } from "./useIconEditor";

const editorStyle = { backgroundColor: "var(--chakra-colors-gray-100)" };
const editorStyle = { backgroundColor: "var(--colors-gray-100)" };

export function IconEditor(props: Props) {
const { ref, position, setPosition, onFileChange, onSave, saving, file } =
Expand Down
3 changes: 0 additions & 3 deletions web/src/theme/components/Button/button.recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export const button = defineRecipe({
variants: {
kind: {
neutral: {
// TODO: Add back when chakra is removed.
// borderWidth: "1px",
// borderColor: "border.default",
backgroundColor: "blackAlpha.100",
_hover: {
background: "gray.100",
Expand Down
2 changes: 0 additions & 2 deletions web/src/theme/components/Input/input.recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export const input = defineRecipe({
backgroundColor: "whiteAlpha.600",
borderColor: "blackAlpha.50",
borderRadius: "lg",
// TODO: Add back when chakra is removed.
// borderWidth: "1px",
boxShadow: "xs",
outline: 0,
position: "relative",
Expand Down
3 changes: 0 additions & 3 deletions web/src/theme/components/Link/link.recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export const link = defineRecipe({
variants: {
kind: {
neutral: {
// TODO: Add back when chakra is removed.
// borderWidth: "1px",
// borderColor: "border.default",
background: "blackAlpha.100",
_hover: {
background: "gray.100",
Expand Down
103 changes: 97 additions & 6 deletions web/src/utils/useDisclosure.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,100 @@
import { UseDisclosureProps, useDisclosure } from "@chakra-ui/react";
import { useCallback, useEffect, useId, useRef, useState } from "react";

// Disclosure
// TODO: Copy into our codebase:
// https://github.com/chakra-ui/chakra-ui/blob/main/packages/hooks/use-disclosure/src/index.ts
export interface UseDisclosureProps {
isOpen?: boolean;
defaultIsOpen?: boolean;
onClose?(): void;
onOpen?(): void;
id?: string;
}

export { useDisclosure };
export type { UseDisclosureProps };
export type WithDisclosure<T> = UseDisclosureProps & T;

type HTMLProps = React.HTMLAttributes<HTMLElement>;

export function useCallbackRef<T extends (...args: any[]) => any>(
callback: T | undefined,
deps: React.DependencyList = [],
) {
const callbackRef = useRef(callback);

useEffect(() => {
callbackRef.current = callback;
});

// eslint-disable-next-line react-hooks/exhaustive-deps
return useCallback(((...args) => callbackRef.current?.(...args)) as T, deps);
}

export function useDisclosure(props: UseDisclosureProps = {}) {
const {
onClose: onCloseProp,
onOpen: onOpenProp,
isOpen: isOpenProp,
id: idProp,
} = props;

const handleOpen = useCallbackRef(onOpenProp);
const handleClose = useCallbackRef(onCloseProp);

const [isOpenState, setIsOpen] = useState(props.defaultIsOpen || false);

const isOpen = isOpenProp !== undefined ? isOpenProp : isOpenState;

const isControlled = isOpenProp !== undefined;

const uid = useId();
const id = idProp ?? `disclosure-${uid}`;

const onClose = useCallback(() => {
if (!isControlled) {
setIsOpen(false);
}
handleClose?.();
}, [isControlled, handleClose]);

const onOpen = useCallback(() => {
if (!isControlled) {
setIsOpen(true);
}
handleOpen?.();
}, [isControlled, handleOpen]);

const onToggle = useCallback(() => {
if (isOpen) {
onClose();
} else {
onOpen();
}
}, [isOpen, onOpen, onClose]);

function getButtonProps(props: HTMLProps = {}): HTMLProps {
return {
...props,
"aria-expanded": isOpen,
"aria-controls": id,
onClick(event) {
props.onClick?.(event);
onToggle();
},
};
}

function getDisclosureProps(props: HTMLProps = {}): HTMLProps {
return {
...props,
hidden: !isOpen,
id,
};
}

return {
isOpen,
onOpen,
onClose,
onToggle,
isControlled,
getButtonProps,
getDisclosureProps,
};
}
Loading

2 comments on commit 5f7dbd5

@vercel
Copy link

@vercel vercel bot commented on 5f7dbd5 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 5f7dbd5 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.