-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from busbud/fix/return-empty-when-slot-no-defi…
…ned-but-accessed fix: fix when slot accessed but not defined
- Loading branch information
Showing
14 changed files
with
293 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/core/tests/configs/setup-for-slot-not-used.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { buttonVariants } from "../setup/setup-for-slot-not-used"; | ||
|
||
describe("test when slot is not defined but others are in variant", () => { | ||
const { icon, root, label } = buttonVariants; | ||
|
||
test("should not have error and do not have extra string", () => { | ||
const expected = "bg-red-500 bg-purple-300"; | ||
expect( | ||
icon({ | ||
appearance: "primary", | ||
size: { | ||
initial: "xs", | ||
lg: "md", | ||
}, | ||
}) | ||
).toBe(expected); | ||
}); | ||
|
||
test("default root", () => { | ||
const expected = "bg-red-100 bg-purple-100 bg-orange-100"; | ||
expect(root()).toBe(expected); | ||
}); | ||
|
||
test("default label", () => { | ||
const expected = "bg-red-300 bg-purple-100 bg-orange-300"; | ||
expect(label()).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { compose } from "../../src/tailwind-buddy"; | ||
|
||
export const buttonVariants = compose({ | ||
slots: { | ||
root: /** @tw */ "bg-red-100", | ||
label: /** @tw */ "bg-red-300", | ||
icon: /** @tw */ "bg-red-500", | ||
}, | ||
variants: { | ||
appearance: { | ||
default: /** @tw */ "bg-purple-100", | ||
primary: /** @tw */ "bg-purple-300", | ||
destructive: /** @tw */ "bg-purple-500", | ||
}, | ||
size: { | ||
xs: { | ||
root: /** @tw */ "bg-yellow-100", | ||
label: /** @tw */ "bg-yellow-300", | ||
}, | ||
sm: { | ||
root: /** @tw */ "bg-blue-100", | ||
label: /** @tw */ "bg-blue-300", | ||
}, | ||
md: { | ||
root: /** @tw */ "bg-orange-100", | ||
label: /** @tw */ "bg-orange-300", | ||
}, | ||
}, | ||
/** Sets the button variant. */ | ||
variant: { | ||
contained: /** @tw */ "", | ||
text: /** @tw */ "", | ||
}, | ||
}, | ||
defaultVariants: { | ||
appearance: "default", | ||
size: "md", | ||
variant: "contained", | ||
}, | ||
responsiveVariants: ["size"], | ||
})(); |
35 changes: 0 additions & 35 deletions
35
packages/core/vite.config.ts.timestamp-1723127702741-1f77ec8ccab97.mjs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import twConfig from "ui-kit/tailwind.config" | ||
import type { Config } from "tailwindcss"; | ||
import tailwindConfig from "ui-kit/tailwind.config"; | ||
|
||
/** @type {import('tailwindcss').Config} */ | ||
export default { | ||
content: [ | ||
"./index.html", | ||
"./src/**/*.{js,ts,jsx,tsx}", | ||
"./node_modules/ui-kit/dist/uikit.js" | ||
"./node_modules/ui-kit/dist/uikit.js", | ||
], | ||
theme: { | ||
extend: twConfig.theme.extend | ||
}, | ||
safelist: twConfig.safelist | ||
} | ||
|
||
theme: tailwindConfig.theme, | ||
safelist: tailwindConfig.safelist, | ||
} satisfies Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { ReactNode } from "react"; | ||
import { type ButtonProps, buttonVariants } from "./Button.variants"; | ||
|
||
const defaultVariants = buttonVariants.definition().defaultVariants; | ||
|
||
export const Button: React.FC<ButtonProps> = ({ | ||
appearance = defaultVariants.appearance, | ||
children, | ||
className, | ||
iconEnd: iconEndProp, | ||
iconStart: iconStartProp, | ||
size = "md", | ||
variant = defaultVariants.variant, | ||
...restProps | ||
}) => { | ||
const { root, icon, label } = buttonVariants; | ||
|
||
const iconContainer = (children: ReactNode) => ( | ||
<span | ||
className={icon({ | ||
appearance, | ||
size, | ||
variant, | ||
})} | ||
> | ||
{children} | ||
</span> | ||
); | ||
|
||
const iconStart = iconStartProp && iconContainer(iconStartProp); | ||
|
||
return ( | ||
<button | ||
className={root({ | ||
appearance, | ||
className, | ||
size, | ||
variant, | ||
})} | ||
{...restProps} | ||
> | ||
{iconStart} | ||
<span className={label({ size })}>{children}</span> | ||
</button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ReactNode } from "react"; | ||
|
||
export interface ButtonBaseProps { | ||
iconEnd?: ReactNode; | ||
iconStart?: ReactNode; | ||
children: ReactNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { compose, VariantsProps } from "@busbud/tailwind-buddy"; | ||
import { ButtonBaseProps } from "@/components/Button/Button.types.ts"; | ||
|
||
export const buttonVariants = compose({ | ||
slots: { | ||
root: /** @tw */ "bg-red-100", | ||
label: /** @tw */ "bg-red-300", | ||
icon: /** @tw */ "bg-red-500", | ||
}, | ||
variants: { | ||
appearance: { | ||
default: "bg-purple-100", | ||
primary: "bg-purple-300", | ||
destructive: "bg-purple-500", | ||
}, | ||
size: { | ||
xs: { | ||
root: "bg-yellow-100", | ||
label: "bg-yellow-300", | ||
}, | ||
sm: { | ||
root: "bg-blue-100", | ||
label: "bg-blue-300", | ||
}, | ||
md: { | ||
root: "bg-orange-100", | ||
label: "bg-orange-300", | ||
}, | ||
}, | ||
/** Sets the button variant. */ | ||
variant: { | ||
contained: "", | ||
text: "", | ||
}, | ||
}, | ||
defaultVariants: { | ||
appearance: "default", | ||
size: "md", | ||
variant: "contained", | ||
}, | ||
responsiveVariants: ["size"], | ||
})<ButtonBaseProps>(); | ||
|
||
export type ButtonProps = VariantsProps<typeof buttonVariants> & | ||
ButtonBaseProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const SearchIcon = () => { | ||
return ( | ||
<svg viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M17.8 18.32a5.9 5.9 0 1 1 .51-.51l-.5.5zm1.24 2.84a8.9 8.9 0 1 1 2.12-2.12l5.74 5.74-2.12 2.12-5.74-5.74z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SearchIcon } from "./Search/Search"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
export { Label } from "./components/Label/Label"; | ||
export type { LabelProps } from "./components/Label/Label.variants"; | ||
export { Dumb } from "./components/Dumb"; | ||
|
||
export { Button } from "./components/Button/Button"; | ||
export { type ButtonProps } from "./components/Button/Button.variants"; | ||
|
||
export { SearchIcon } from "./components/Icons/Search/Search"; |
Oops, something went wrong.