-
-
Notifications
You must be signed in to change notification settings - Fork 565
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
1 parent
77fa995
commit ac8eaef
Showing
11 changed files
with
123 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,28 +1,38 @@ | ||
import { mergeClasses, toKebabCase } from "./utils" | ||
import type { AstroComponentFactory } from "astro/runtime/server/render/astro/factory.js" | ||
import { mergeClasses, toKebabCase } from './utils'; | ||
import type { AstroComponentFactory } from 'astro/runtime/server/render/astro/factory.js'; | ||
import type { IconNode } from './types'; | ||
import { | ||
render, | ||
renderSlot, | ||
createAstro, | ||
createComponent, | ||
renderComponent, | ||
} from "astro/compiler-runtime" | ||
} from 'astro/compiler-runtime'; | ||
import Icon from './Icon.astro'; | ||
|
||
export default (iconName: string, iconNode: IconNode): AstroComponentFactory => { | ||
const Component = createComponent(($$result, $$props, $$slots) => { | ||
const $$Astro = createAstro(undefined); | ||
const Astro = $$result.createAstro($$Astro, $$props, $$slots); | ||
const { class: className, ...restProps } = Astro.props; | ||
return render`${renderComponent($$result, 'Icon', Icon, { | ||
class: mergeClasses( | ||
Boolean(iconName) && `lucide-${toKebabCase(iconName)}`, | ||
Boolean(className) && className | ||
), | ||
iconNode, | ||
...restProps, | ||
}, { "default": () => render`${renderSlot($$result, $$slots["default"])}`, })}`; | ||
}, undefined, "none"); | ||
const Component = createComponent( | ||
($$result, $$props, $$slots) => { | ||
const $$Astro = createAstro(undefined); | ||
const Astro = $$result.createAstro($$Astro, $$props, $$slots); | ||
const { class: className, ...restProps } = Astro.props; | ||
return render`${renderComponent( | ||
$$result, | ||
'Icon', | ||
Icon, | ||
{ | ||
class: mergeClasses( | ||
Boolean(iconName) && `lucide-${toKebabCase(iconName)}`, | ||
Boolean(className) && className, | ||
), | ||
iconNode, | ||
...restProps, | ||
}, | ||
{ default: () => render`${renderSlot($$result, $$slots['default'])}` }, | ||
)}`; | ||
}, | ||
undefined, | ||
'none', | ||
); | ||
return Component; | ||
} | ||
}; |
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
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
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
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,2 +1,2 @@ | ||
export * from "./render" | ||
export * from "./types" | ||
export * from './render'; | ||
export * from './types'; |
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,24 +1,34 @@ | ||
import type { queries, BoundFunctions } from '@testing-library/dom' | ||
import type { ContainerRenderOptions } from "astro/container"; | ||
import type { ComponentProps } from "astro/types" | ||
import type { AstroComponentFactory } from "astro/runtime/server/index.js"; | ||
import type { queries, BoundFunctions } from '@testing-library/dom'; | ||
import type { ContainerRenderOptions } from 'astro/container'; | ||
import type { ComponentProps } from 'astro/types'; | ||
import type { AstroComponentFactory } from 'astro/runtime/server/index.js'; | ||
|
||
export type RenderFn = <T = PossibleComponentType>(AstroComponent: T, options?: RenderFnOptions<T>) => RenderResult | ||
export type RenderFn = <T = PossibleComponentType>( | ||
AstroComponent: T, | ||
options?: RenderFnOptions<T>, | ||
) => RenderResult; | ||
|
||
type RenderFnOptions<T> = T extends AstroComponentVirtualType ? ContainerRenderOptionsWithInferedProps<T> : ContainerRenderOptions | ||
type RenderFnOptions<T> = T extends AstroComponentVirtualType | ||
? ContainerRenderOptionsWithInferedProps<T> | ||
: ContainerRenderOptions; | ||
|
||
type RenderResult = Promise<{ | ||
container: HTMLElement; | ||
html: string; | ||
} & Queries> | ||
type RenderResult = Promise< | ||
{ | ||
container: HTMLElement; | ||
html: string; | ||
} & Queries | ||
>; | ||
|
||
type ContainerRenderOptionsWithInferedProps<T extends AstroComponentVirtualType> = Omit<ContainerRenderOptions, "props"> & { | ||
props?: ComponentProps<T> | ||
} | ||
type ContainerRenderOptionsWithInferedProps<T extends AstroComponentVirtualType> = Omit< | ||
ContainerRenderOptions, | ||
'props' | ||
> & { | ||
props?: ComponentProps<T>; | ||
}; | ||
|
||
// types may either be coming from the compiler (through the language tools) | ||
// or from the Astro component's signature itself | ||
type PossibleComponentType = AstroComponentFactory | AstroComponentVirtualType | ||
type PossibleComponentType = AstroComponentFactory | AstroComponentVirtualType; | ||
type AstroComponentVirtualType = (args: any) => any; | ||
|
||
type Queries = BoundFunctions<typeof queries> | ||
type Queries = BoundFunctions<typeof queries>; |
Oops, something went wrong.