Skip to content

Commit 7adf2a4

Browse files
authored
chore: Format (#127)
* chore: Rename prettier script to avoid clashes w/ direct calls * chore: Formatting
1 parent 6fabf0a commit 7adf2a4

File tree

4 files changed

+52
-47
lines changed

4 files changed

+52
-47
lines changed

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ Any Preact component can be registered as a custom element simply by importing `
1010
```javascript
1111
import register from 'preact-custom-element';
1212

13-
const Greeting = ({ name = 'World' }) => (
14-
<p>Hello, {name}!</p>
15-
);
13+
const Greeting = ({ name = 'World' }) => <p>Hello, {name}!</p>;
1614

1715
register(Greeting, 'x-greeting', ['name'], { shadow: true, mode: 'open', adoptedStyleSheets: [], serializable: true });
1816
// ^ ^ ^ ^ ^ ^ ^
1917
// | HTML tag name | use shadow-dom | use adoptedStyleSheets |
2018
// Component definition Observed attributes Encapsulation mode for the shadow DOM tree Root is serializable
2119
```
2220

23-
> _**\* Note:** as per the [Custom Elements specification](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name), the tag name must contain a hyphen._
21+
> _**Note:** as per the [Custom Elements specification](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name), the tag name must contain a hyphen._
2422
2523
Use the new tag name in HTML, attribute keys and values will be passed in as props:
2624

@@ -50,15 +48,15 @@ import register from 'preact-custom-element';
5048

5149
// <x-greeting name="Bo"></x-greeting>
5250
class Greeting extends Component {
53-
// Register as <x-greeting>:
54-
static tagName = 'x-greeting';
51+
// Register as <x-greeting>:
52+
static tagName = 'x-greeting';
5553

56-
// Track these attributes:
57-
static observedAttributes = ['name'];
54+
// Track these attributes:
55+
static observedAttributes = ['name'];
5856

59-
render({ name }) {
60-
return <p>Hello, {name}!</p>;
61-
}
57+
render({ name }) {
58+
return <p>Hello, {name}!</p>;
59+
}
6260
}
6361
register(Greeting);
6462
```
@@ -68,12 +66,16 @@ If no `observedAttributes` are specified, they will be inferred from the keys of
6866
```js
6967
// Other option: use PropTypes:
7068
function FullName({ first, last }) {
71-
return <span>{first} {last}</span>
69+
return (
70+
<span>
71+
{first} {last}
72+
</span>
73+
);
7274
}
7375

7476
FullName.propTypes = {
75-
first: Object, // you can use PropTypes, or this
76-
last: Object // trick to define untyped props.
77+
first: Object, // you can use PropTypes, or this
78+
last: Object, // trick to define untyped props.
7779
};
7880

7981
register(FullName, 'full-name');
@@ -87,21 +89,21 @@ When using shadow DOM, you can make use of named `<slot>` elements in your compo
8789

8890
```jsx
8991
function TextSection({ heading, content }) {
90-
return (
91-
<div>
92-
<h2>{heading}</h2>
93-
<p>{content}</p>
94-
</div>
95-
);
92+
return (
93+
<div>
94+
<h2>{heading}</h2>
95+
<p>{content}</p>
96+
</div>
97+
);
9698
}
9799

98100
register(TextSelection, 'text-selection', [], { shadow: true });
99101
```
100102

101103
```html
102104
<text-section>
103-
<span slot="heading">My Heading</span>
104-
<span slot="content">Some content goes here.</span>
105+
<span slot="heading">My Heading</span>
106+
<span slot="content">Some content goes here.</span>
105107
</text-section>
106108
```
107109

jsconfig.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"compilerOptions": {
3-
"target": "ESNext",
4-
"module": "NodeNext",
5-
"moduleResolution": "Node",
6-
"noEmit": true,
7-
"allowJs": true,
8-
"checkJs": true,
9-
"skipLibCheck": false,
10-
"jsx": "react",
11-
"jsxFactory": "h",
12-
"jsxFragmentFactory": "Fragment",
13-
}
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "NodeNext",
5+
"moduleResolution": "Node",
6+
"noEmit": true,
7+
"allowJs": true,
8+
"checkJs": true,
9+
"skipLibCheck": false,
10+
"jsx": "react",
11+
"jsxFactory": "h",
12+
"jsxFragmentFactory": "Fragment"
13+
}
1414
}

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
"scripts": {
1111
"prepare": "npx simple-git-hooks",
1212
"build": "microbundle -f cjs,es,umd --no-generateTypes",
13-
"lint": "eslint src/*.js",
1413
"test": "npm run test:types & npm run test:browser",
1514
"test:browser": "wtr test/browser/*.test.{js,jsx}",
1615
"test:types": "tsc -p test/types/",
17-
"prettier": "prettier **/*.{js,jsx} --write",
16+
"lint": "eslint src/*.js",
17+
"format": "prettier --write --ignore-path .gitignore '!README.md' .",
1818
"prepublishOnly": "npm run build && npm run lint && npm run test"
1919
},
2020
"eslintConfig": {
@@ -24,7 +24,10 @@
2424
"version": "16.8"
2525
}
2626
},
27-
"ignorePatterns": ["*.ts", "*.tsx"],
27+
"ignorePatterns": [
28+
"*.ts",
29+
"*.tsx"
30+
],
2831
"rules": {
2932
"brace-style": "off",
3033
"jest/expect-expect": "off",

test/types/tsconfig.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"compilerOptions": {
3-
"target": "ESNext",
4-
"module": "NodeNext",
5-
"moduleResolution": "NodeNext",
6-
"noEmit": true,
7-
"skipLibCheck": true,
8-
"jsx": "react",
9-
"jsxFactory": "h",
10-
"jsxFragmentFactory": "Fragment",
11-
},
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"noEmit": true,
7+
"skipLibCheck": true,
8+
"jsx": "react",
9+
"jsxFactory": "h",
10+
"jsxFragmentFactory": "Fragment"
11+
}
1212
}

0 commit comments

Comments
 (0)