-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from c4tastic/feat/children-handling
- Loading branch information
Showing
8 changed files
with
111 additions
and
15 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
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,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<script type="module" src="./lit/example/Example.lit.ts"></script> | ||
<script type="module" src="./lit/example-with-custom-event/ExampleEvent.lit.ts"></script> | ||
<script type="module" src="./index.tsx"></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
<script type="module" src="./lit/example/Example.lit.ts"></script> | ||
<script | ||
type="module" | ||
src="./lit/example-with-custom-event/ExampleEvent.lit.ts" | ||
></script> | ||
<script | ||
type="module" | ||
src="./lit/example/ExampleWithChildren.lit.ts" | ||
></script> | ||
<script type="module" src="./index.tsx"></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
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,22 @@ | ||
import { html, LitElement, customElement, css } from 'lit-element' | ||
import { WITH_CHILDREN_TAG_NAME } from './Example.models' | ||
|
||
@customElement(WITH_CHILDREN_TAG_NAME) | ||
export class ExampleWithChildren extends LitElement { | ||
static styles = css` | ||
:host { | ||
border: 1px solid #222; | ||
padding: 0.5rem; | ||
} | ||
` | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
render() { | ||
return html`<slot></slot> <slot name="emoji"></slot>` | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
readonly [WITH_CHILDREN_TAG_NAME]: ExampleWithChildren | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
example/react/example-with-children/ExampleWithChildren.react.tsx
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,26 @@ | ||
import type { HTMLAttributes, ReactElement } from 'react' | ||
import { forwardRef } from 'react' | ||
import { createWrapper, slottedNode } from '../../../src' | ||
import type { ExampleWithChildren } from '../../lit/example/ExampleWithChildren.lit' | ||
import { WITH_CHILDREN_TAG_NAME as tagName } from '../../lit/example/Example.models' | ||
|
||
interface WithChildrenProps extends HTMLAttributes<ExampleWithChildren> { | ||
readonly emoji?: ReactElement | ||
} | ||
|
||
export const WithChildren = forwardRef< | ||
ExampleWithChildren | null, | ||
WithChildrenProps | ||
>(({ emoji, children, ...props }, ref) => | ||
createWrapper<ExampleWithChildren>({ | ||
tagName, | ||
ref, | ||
props, | ||
children: ( | ||
<> | ||
{children} | ||
{emoji && slottedNode(emoji, 'emoji')} | ||
</> | ||
), | ||
}) | ||
) |
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 +1 @@ | ||
export { createWrapper } from './wrapper' | ||
export { createWrapper, slottedNode } from './wrapper' |
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