-
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.
- Loading branch information
Showing
9 changed files
with
128 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { generateSafeList } from "./utils/tailwind-utils"; | ||
export { compose } from "./tailwind-buddy" | ||
export type { VariantsProps } from "./tailwind-buddy" | ||
export { compose } from "./tailwind-buddy"; | ||
export type { VariantsProps } from "./types/definition"; |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { MergedProps } from "./props"; | ||
import type { Slots } from "./slots"; | ||
import type { | ||
Variants, | ||
CompoundVariant, | ||
DefaultVariants, | ||
ResponsiveVariants, | ||
} from "./variants"; | ||
|
||
export type TB = < | ||
V extends Variants<S>, | ||
CV extends CompoundVariant<V, S>, | ||
DV extends DefaultVariants<V, S>, | ||
R extends ResponsiveVariants<V>, | ||
S extends Slots | ||
>(options: { | ||
slots: S; | ||
variants?: V; | ||
compoundVariants?: CV[]; | ||
responsiveVariants?: R; | ||
defaultVariants: DV; | ||
}) => <Props>() => { | ||
[Slot in keyof S]: (props?: MergedProps<Props, V, R>) => string; | ||
} & { | ||
definition: () => { | ||
slots: S; | ||
variants?: V; | ||
compoundVariants?: CV[]; | ||
responsiveVariants?: R; | ||
defaultVariants: DV; | ||
}; | ||
}; | ||
|
||
export type VariantsProps< | ||
V extends Record<string, (...args: any[]) => unknown> | ||
> = Parameters<V[keyof V]>[0]; |
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,13 @@ | ||
import { ResponsiveVariant, ResponsiveVariants } from "./variants"; | ||
|
||
export type MergedProps<Props, V, R extends ResponsiveVariants<V>> = { | ||
className?: string; | ||
} & { | ||
[K in keyof V]?: R extends undefined | ||
? keyof V[K] | ||
: K extends R[number] | ||
? ResponsiveVariant<V, K> | keyof V[K] | ||
: keyof V[K]; | ||
} & { | ||
[K in keyof Props]?: Props[K]; | ||
}; |
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,5 @@ | ||
// interface GlobalScreens { | ||
// screens: string[]; | ||
// } | ||
|
||
export type Screens = ["sm", "md", "lg", "xl"]; |
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,4 @@ | ||
export type Slots = { | ||
[slot: string]: string; | ||
root: string; | ||
}; |
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,36 @@ | ||
import { Screens } from "./screens"; | ||
import { Slots } from "./slots"; | ||
|
||
export type ResponsiveVariants<V> = (keyof V)[]; | ||
|
||
export type Variants<S extends Slots> = { | ||
[variant: string]: { | ||
[kind: string]: | ||
| string | ||
| { | ||
[key in keyof S]?: string; | ||
}; | ||
}; | ||
}; | ||
|
||
export type DefaultVariants<V extends Variants<S>, S extends Slots> = { | ||
[K in keyof V]: K extends keyof V ? keyof V[K] : never; | ||
}; | ||
|
||
export type CompoundVariant<V extends Variants<S>, S extends Slots> = { | ||
conditions: { | ||
[K in keyof V]?: | ||
| (K extends keyof V ? keyof V[K] : never) | ||
| (K extends keyof V ? keyof V[K] : never)[] | ||
| boolean; | ||
} & { | ||
[K in string]?: string | string[] | boolean; | ||
}; | ||
class: string | Record<string, string>; | ||
}; | ||
|
||
export type ResponsiveVariant<V, K extends keyof V> = { | ||
["initial"]: keyof V[K]; | ||
} & { | ||
[screen in Screens[number]]?: keyof V[K]; | ||
}; |
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,20 @@ | ||
export const buildArrayWithResponsivesFromDefault = ( | ||
obj: Record<string, any> | ||
): any[] => { | ||
const acc: any[] = []; | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (value === undefined || value === null) continue; | ||
else if (typeof value === "object") { | ||
if (typeof value["initial"] === "undefined") { | ||
throw new Error( | ||
`initial value is missing for the variant ${key} ${value}` | ||
); | ||
} else { | ||
acc.push([key, value]); | ||
} | ||
} else { | ||
acc.push([key, { initial: value }]); | ||
} | ||
} | ||
return acc; | ||
}; |
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,6 @@ | ||
export function extractValueFromVariantSlot(value: any, slot: string) { | ||
if (typeof value === "string") return value.replace(/\s+/g, " ").trim(); | ||
else if (value?.[slot] && typeof value[slot] === "string") | ||
return value[slot].replace(/\s+/g, " ").trim(); | ||
return undefined; | ||
} |