-
Notifications
You must be signed in to change notification settings - Fork 14
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 #21 from break-stuff/add-preact-integration
Add JSX integration
- Loading branch information
Showing
50 changed files
with
20,908 additions
and
11,081 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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import type { RadioGroup, InterfaceEventType } from "./types/radio-group/RadioGroup.d.ts"; | ||
import type { RadioButton } from "./types/radio-button/RadioButton.d.ts"; | ||
|
||
/** | ||
* This type can be used to create scoped tags for your components. | ||
* | ||
* Usage: | ||
* | ||
* ```ts | ||
* import type { ScopedElements } from "path/to/library/jsx-integration"; | ||
* | ||
* declare module "my-library" { | ||
* namespace JSX { | ||
* interface IntrinsicElements | ||
* extends ScopedElements<'test-', ''> {} | ||
* } | ||
* } | ||
* ``` | ||
* | ||
*/ | ||
export type ScopedElements<Prefix extends string = "", Suffix extends string = ""> = { | ||
[Key in keyof CustomElements as `${Prefix}${Key}${Suffix}`]: CustomElements[Key]; | ||
}; | ||
|
||
type BaseProps = { | ||
/** Content added between the opening and closing tags of the element */ | ||
children?: any; | ||
/** Used for declaratively styling one or more elements using CSS (Cascading Stylesheets) */ | ||
class?: string; | ||
/** Takes an object where the key is the class name(s) and the value is a boolean expression. When true, the class is applied, and when false, it is removed. */ | ||
classList?: Record<string, boolean | undefined>; | ||
/** Contains a space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the ::part pseudo-element. */ | ||
part?: string; | ||
/** Contains a space-separated list of the part names of the element that should be exposed on the host element. */ | ||
exportparts?: string; | ||
/** Adds a reference for a custom element slot */ | ||
slot?: string; | ||
/** Prop for setting inline styles */ | ||
style?: Record<string, string | number>; | ||
}; | ||
|
||
type BaseEvents = {}; | ||
|
||
type RadioGroupProps = { | ||
/** The value assigned to the radio button. This will reflect in the radio group when clicked. */ | ||
value?: RadioGroup["value"]; | ||
/** Disables the radio group and all of its radio buttons */ | ||
disabled?: RadioGroup["disabled"]; | ||
/** This will control the size of the radio buttons */ | ||
size?: RadioGroup["size"]; | ||
/** This is a test for internal options */ | ||
variants?: RadioGroup["variants"]; | ||
/** This is a test for external d.ts options */ | ||
external?: RadioGroup["external"]; | ||
/** This is a test for external .ts options */ | ||
external2?: RadioGroup["external2"]; | ||
/** This is a test for options from an object */ | ||
complex?: RadioGroup["complex"]; | ||
/** This is a camel-case attribute */ | ||
"my-attribute"?: RadioGroup["myAttribute"]; | ||
|
||
/** some description for custom-event */ | ||
onCustomEvent?: (e: CustomEvent<never>) => void; | ||
/** some description for typed-event */ | ||
onTypedEvent?: (e: CustomEvent<HTMLInputElement>) => void; | ||
/** some description for typed-custom-event */ | ||
onTypedCustomEvent?: (e: CustomEvent<InterfaceEventType>) => void; | ||
}; | ||
|
||
type RadioButtonProps = { | ||
/** The value assigned to the radio button. This will reflect in the radio group when clicked. */ | ||
value?: RadioButton["value"]; | ||
/** Disables the radio button */ | ||
disabled?: RadioButton["disabled"]; | ||
/** A lookup type for example */ | ||
target?: RadioButton["target"]; | ||
}; | ||
|
||
export type CustomElements = { | ||
/** | ||
* | ||
* Radio groups are used to group multiple radios or radio buttons, so they function as a single form control. Here is its [documentation](https://github.com/microsoft/vscode-custom-data/blob/master/samples/webcomponents/src/components/my-component/docs.md). | ||
* | ||
* Use it like this: | ||
* ```html | ||
* <radio-group value="2" size="3"> | ||
* <span slot="label">My Label</span> | ||
* <radio-button value="1">Option 1</radio-button> | ||
* <radio-button value="2">Option 2</radio-button> | ||
* <radio-button value="3">Option 3</radio-button> | ||
* </radio-group> | ||
* ``` | ||
* --- | ||
* | ||
* | ||
* ### **Events:** | ||
* - **custom-event** - some description for custom-event | ||
* - **typed-event** - some description for typed-event | ||
* - **typed-custom-event** - some description for typed-custom-event | ||
* | ||
* ### **Methods:** | ||
* - **validate()** - Validated the radio inputs | ||
* - **checkStatus(value: _string_, message: _string_): _string_** - This is a test method with parameters | ||
* | ||
* | ||
* ### **Slots:** | ||
* - _default_ - add radio buttons to the `default` slot to create options to your radio group | ||
* - **label** - placeholder for the radio group label | ||
* | ||
* ### **CSS Properties:** | ||
* - **--radio-border-radius** - Controls the border radius of the radio buttons _(default: undefined)_ | ||
* - **--radio-background-color** - Controls the color of bar _(default: red)_ | ||
* | ||
* ### **CSS Parts:** | ||
* - **radio-label** - Applies custom styles the radio group label | ||
*/ | ||
"radio-group": Partial<RadioGroupProps | BaseProps | BaseEvents>; | ||
|
||
/** | ||
* Radio buttons allow users to select a single option from a group. Here is its [documentation](https://my-site.com/documentation). | ||
* | ||
* Use it like this: | ||
* ```html | ||
* <radio-button value="1" disabled>Your label</radio-button> | ||
* ``` | ||
* --- | ||
* | ||
* | ||
* ### **Slots:** | ||
* - _default_ - add text here to label your radio button | ||
*/ | ||
"radio-button": Partial<RadioButtonProps | BaseProps | BaseEvents>; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="color-scheme" content="light dark" /> | ||
<title>Vite + Preact</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"preact": "^10.13.1", | ||
"lit-app": "*" | ||
}, | ||
"devDependencies": { | ||
"@preact/preset-vite": "^2.5.0", | ||
"typescript": "^5.2.2", | ||
"vite": "^4.3.2" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,8 @@ | ||
import type { CustomElements, ScopedElements } from "lit-app/custom-element-jsx"; | ||
|
||
declare module "preact" { | ||
namespace JSX { | ||
interface IntrinsicElements | ||
extends CustomElements {} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,47 @@ | ||
import { render } from 'preact'; | ||
import preactLogo from './assets/preact.svg'; | ||
import './style.css'; | ||
|
||
export function App() { | ||
return ( | ||
<div> | ||
<a href="https://preactjs.com" target="_blank"> | ||
<img src={preactLogo} alt="Preact logo" height="160" width="160" /> | ||
</a> | ||
<h1>Get Started building Vite-powered Preact Apps </h1> | ||
<section> | ||
<Resource | ||
title="Learn Preact" | ||
description="If you're new to Preact, try the interactive tutorial to learn important concepts" | ||
href="https://preactjs.com/tutorial" | ||
/> | ||
<Resource | ||
title="Differences to React" | ||
description="If you're coming from React, you may want to check out our docs to see where Preact differs" | ||
href="https://preactjs.com/guide/v10/differences-to-react" | ||
/> | ||
<Resource | ||
title="Learn Vite" | ||
description="To learn more about Vite and how you can customize it to fit your needs, take a look at their excellent documentation" | ||
href="https://vitejs.dev" | ||
/> | ||
<radio-group> | ||
<radio-button></radio-button> | ||
<radio-button></radio-button> | ||
<radio-button></radio-button> | ||
</radio-group> | ||
</section> | ||
</div> | ||
); | ||
} | ||
|
||
function Resource(props) { | ||
return ( | ||
<a href={props.href} target="_blank" class="resource"> | ||
<h2>{props.title}</h2> | ||
<p>{props.description}</p> | ||
</a> | ||
); | ||
} | ||
|
||
render(<App />, document.getElementById('app')); |
Oops, something went wrong.