Skip to content

Commit

Permalink
Pass appkit config to css function
Browse files Browse the repository at this point in the history
We should not rely on a hook in a function
working, so better let the calling component
pass it.
  • Loading branch information
Arnei committed May 29, 2024
1 parent d316d89 commit 9ccf240
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Interpolation, Theme } from "@emotion/react";
import { focusStyle, match, useAppkitConfig } from ".";
import { AppkitConfig, focusStyle, match, useAppkitConfig } from ".";

/**
* A mostly unstyled button used to build buttons. Always use this instead of
Expand Down Expand Up @@ -33,18 +33,24 @@ type ButtonProps = JSX.IntrinsicElements["button"] & {

/** A styled button */
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ kind = "normal", extraCss, children, ...rest }, ref) => (
<button ref={ref} type="button" css={css(kind, extraCss)} {...rest}>{children}</button>
),
({ 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".
*/
const css = (kind: Kind, extraCss: Interpolation<Theme> = {}): Interpolation<Theme> => {
const config = useAppkitConfig();

const css = (
config: AppkitConfig,
kind: Kind,
extraCss: Interpolation<Theme> = {}
): Interpolation<Theme> => {
const notDisabledStyle = match(kind, {
"normal": () => ({
border: `1px solid ${config.colors.neutral40}`,
Expand Down

0 comments on commit 9ccf240

Please sign in to comment.