@progressive-development/pd-content 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,29 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ indent_size = 2
25
+
26
+ [*.{html,js,md}]
27
+ block_comment_start = /**
28
+ block_comment = *
29
+ block_comment_end = */
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ stories: ['../stories/**/*.stories.{js,md,mdx}'],
3
+ };
@@ -0,0 +1,8 @@
1
+ import { storybookPlugin } from '@web/dev-server-storybook';
2
+ import baseConfig from '../web-dev-server.config.mjs';
3
+
4
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
5
+ ...baseConfig,
6
+ open: '/',
7
+ plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
8
+ });
package/LICENSE ADDED
@@ -0,0 +1,2 @@
1
+ No License, all rights reserved
2
+ @2021 - PD Progressive Development UG
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # \<pd-content>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i pd-content
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import 'pd-content/pd-content.js';
16
+ </script>
17
+
18
+ <pd-content></pd-content>
19
+ ```
20
+
21
+ ## Linting and formatting
22
+
23
+ To scan the project for linting and formatting errors, run
24
+
25
+ ```bash
26
+ npm run lint
27
+ ```
28
+
29
+ To automatically fix linting and formatting errors, run
30
+
31
+ ```bash
32
+ npm run format
33
+ ```
34
+
35
+ ## Testing with Web Test Runner
36
+
37
+ To execute a single test run:
38
+
39
+ ```bash
40
+ npm run test
41
+ ```
42
+
43
+ To run the tests in interactive watch mode run:
44
+
45
+ ```bash
46
+ npm run test:watch
47
+ ```
48
+
49
+ ## Demoing with Storybook
50
+
51
+ To run a local instance of Storybook for your component, run
52
+
53
+ ```bash
54
+ npm run storybook
55
+ ```
56
+
57
+ To build a production version of Storybook, run
58
+
59
+ ```bash
60
+ npm run storybook:build
61
+ ```
62
+
63
+
64
+ ## Tooling configs
65
+
66
+ For most of the tools, the configuration is in the `package.json` to minimize the amount of files in your project.
67
+
68
+ If you customize the configuration a lot, you can consider moving them to individual files.
69
+
70
+ ## Local Demo with `web-dev-server`
71
+
72
+ ```bash
73
+ npm start
74
+ ```
75
+
76
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,29 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <style>
6
+ body {
7
+ background: #fafafa;
8
+ }
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <div id="demo"></div>
13
+
14
+ <script type="module">
15
+ import { html, render } from 'lit';
16
+ import '../pd-content.js';
17
+
18
+ const title = 'Hello owc World!';
19
+ render(
20
+ html`
21
+ <pd-content .title=${title}>
22
+ some light-dom
23
+ </pd-content>
24
+ `,
25
+ document.querySelector('#demo')
26
+ );
27
+ </script>
28
+ </body>
29
+ </html>
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { PdContent } from './src/PdContent.js';
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@progressive-development/pd-content",
3
+ "description": "Progressive Development content components. ",
4
+ "license": "SEE LICENSE IN LICENSE",
5
+ "author": "PD Progressive Development UG",
6
+ "version": "0.0.1",
7
+ "main": "index.js",
8
+ "module": "index.js",
9
+ "scripts": {
10
+ "analyze": "cem analyze --litelement",
11
+ "start": "web-dev-server",
12
+ "lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
13
+ "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
14
+ "test": "web-test-runner --coverage",
15
+ "test:watch": "web-test-runner --watch",
16
+ "storybook": "npm run analyze -- --exclude dist && web-dev-server -c .storybook/server.mjs",
17
+ "storybook:build": "npm run analyze -- --exclude dist && build-storybook"
18
+ },
19
+ "dependencies": {
20
+ "lit": "^2.0.2",
21
+ "@progressive-development/pd-icon": "0.0.2"
22
+ },
23
+ "devDependencies": {
24
+ "@custom-elements-manifest/analyzer": "^0.4.17",
25
+ "@open-wc/eslint-config": "^4.3.0",
26
+ "@open-wc/testing": "next",
27
+ "@web/dev-server": "^0.1.25",
28
+ "@web/dev-server-storybook": "next",
29
+ "@web/test-runner": "^0.13.20",
30
+ "eslint": "^7.32.0",
31
+ "eslint-config-prettier": "^8.3.0",
32
+ "husky": "^4.3.8",
33
+ "lint-staged": "^10.5.4",
34
+ "prettier": "^2.4.1"
35
+ },
36
+ "customElements": "custom-elements.json",
37
+ "eslintConfig": {
38
+ "extends": [
39
+ "@open-wc",
40
+ "prettier"
41
+ ]
42
+ },
43
+ "prettier": {
44
+ "singleQuote": true,
45
+ "arrowParens": "avoid"
46
+ },
47
+ "husky": {
48
+ "hooks": {
49
+ "pre-commit": "lint-staged"
50
+ }
51
+ },
52
+ "lint-staged": {
53
+ "*.js": [
54
+ "eslint --fix",
55
+ "prettier --write"
56
+ ]
57
+ },
58
+ "keywords": [
59
+ "pd",
60
+ "progressive",
61
+ "development",
62
+ "content",
63
+ "collapse"
64
+ ]
65
+ }
package/pd-collapse.js ADDED
@@ -0,0 +1,3 @@
1
+ import { PdCollapse } from './src/PdCollapse.js';
2
+
3
+ window.customElements.define('pd-collapse', PdCollapse);
@@ -0,0 +1,204 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
4
+ */
5
+
6
+ import { css, html, LitElement } from 'lit';
7
+ import '@progressive-development/pd-icon';
8
+
9
+ export class PdCollapse extends LitElement {
10
+ static get properties() {
11
+ return {
12
+ active: { type: Boolean },
13
+ popup: { type: Boolean },
14
+ icon: { type: String },
15
+ };
16
+ }
17
+
18
+ constructor() {
19
+ super();
20
+ this.active = false;
21
+ this.popup = false;
22
+ this.icon = 'toggleCollapse';
23
+ }
24
+
25
+ static get styles() {
26
+ return [
27
+ css`
28
+ :host {
29
+ /* Define customizeabled props */
30
+ --my-content-background-color: var(--squi-background-color, white);
31
+
32
+ --my-header-background-color: var(--squi-background-color, #084c61);
33
+ --my-header-background-hover-color: var(
34
+ --squi-background-hover-color,
35
+ #177e89
36
+ );
37
+ --my-header-font-color: var(--app-display-font, white);
38
+
39
+ --my-icon-fill-color: var(--squi-text-color, white);
40
+ --my-icon-fill-active-color: var(--squi-text-color, white);
41
+
42
+ --my-icon-fill-hover-color: var(--squi-text-color, yellow);
43
+ --my-icon-fill-active-hover-color: var(--squi-text-color, yellow);
44
+
45
+ --my-border-px: var(--squi-border-px, 1px);
46
+ --my-border-gradient-color1: var(
47
+ --squi-background-gradient-color1,
48
+ #24a3b9
49
+ );
50
+ --my-border-gradient-color2: var(
51
+ --squi-background-gradient-color2,
52
+ #23636e
53
+ );
54
+
55
+ --my-font: var(--app-display-font, Oswald);
56
+
57
+ display: block;
58
+ width: 100%;
59
+ position: relative;
60
+ overflow: visible;
61
+
62
+ --squi-icon-fill: var(--my-icon-fill-color);
63
+ --squi-icon-fill-active: var(--my-icon-fill-active-color);
64
+ }
65
+ :host([popup]) {
66
+ position: unset;
67
+ }
68
+ :host .content.open {
69
+ border: 10px solid;
70
+ border-image-slice: 1;
71
+ border-width: var(--my-border-px);
72
+ border-image-source: linear-gradient(
73
+ to left,
74
+ var(--my-border-gradient-color1),
75
+ var(--my-border-gradient-color2)
76
+ );
77
+ box-shadow: var(--squi-box-shadow);
78
+ background: var(--my-content-background-color);
79
+ margin-bottom: 1rem;
80
+ position: relative;
81
+ overflow: visible;
82
+ }
83
+ :host([popup]) .content.open {
84
+ border: 0;
85
+ position: absolute;
86
+ top: 0;
87
+ right: 0;
88
+ left: 0;
89
+ height: 100%;
90
+ background: radial-gradient(
91
+ var(--game-color-light),
92
+ var(--game-color-dark)
93
+ ); /* ToDo */
94
+ overflow-y: auto;
95
+ z-index: 2;
96
+ margin-bottom: 0;
97
+ }
98
+ /*
99
+ :host([active]) {
100
+ visibility: visible;
101
+ }
102
+ */
103
+ ::slotted(.header) {
104
+ display: flex;
105
+ align-items: center;
106
+ }
107
+ .trigger {
108
+ background: var(--my-header-background-color);
109
+ font-family: var(--my-font);
110
+ box-shadow: var(--squi-box-shadow);
111
+ color: var(--my-header-font-color);
112
+ transition-property: box-shadow, background;
113
+ transition: 0.2s ease-in;
114
+ cursor: pointer;
115
+ font-size: 1rem;
116
+ padding: 0.5rem;
117
+ display: flex;
118
+ justify-content: space-between;
119
+ box-sizing: border-box;
120
+ position: relative;
121
+ }
122
+ .trigger:hover {
123
+ box-shadow: 1px 1px 2px rgb(var(--raw-game-color-dark-darker, grey)); /* ToDo*/
124
+ background: var(--my-header-background-hover-color);
125
+ --squi-icon-fill: var(--my-icon-fill-hover-color);
126
+ --squi-icon-fill-active: var(--my-icon-fill-active-hover-color);
127
+ }
128
+ .trigger.closed {
129
+ margin-bottom: 1rem;
130
+ }
131
+ .content {
132
+ will-change: transform;
133
+ height: 0;
134
+ overflow: hidden;
135
+ transition-property: visibility, transform;
136
+ transition-duration: 0.2s;
137
+ visibility: hidden;
138
+ transform: translate3d(0, -100%, 0);
139
+ box-sizing: border-box;
140
+ }
141
+ .content.open {
142
+ visibility: visible;
143
+ height: auto;
144
+ transform: translate3d(0, 0, 0);
145
+ overflow-y: auto;
146
+ }
147
+ .open .close-link {
148
+ position: fixed;
149
+ right: 0;
150
+ --squi-icon-fill: var(--app-primary-color);
151
+ --squi-icon-fill-active: var(--game-color-dark);
152
+ }
153
+ @media (min-width: 460px) {
154
+ :host {
155
+ }
156
+ }
157
+ `,
158
+ ];
159
+ }
160
+
161
+ open() {
162
+ this.active = true;
163
+ }
164
+
165
+ close() {
166
+ this.active = false;
167
+ }
168
+
169
+ onClick() {
170
+ this.active = !this.active;
171
+ this.dispatchEvent(
172
+ new CustomEvent('toggle-accordion', {
173
+ bubbles: true,
174
+ composed: true,
175
+ detail: this.active,
176
+ })
177
+ );
178
+ }
179
+
180
+ render() {
181
+ // eslint-disable-next-line lit-a11y/click-events-have-key-events
182
+ return html`<div
183
+ class="trigger ${this.active ? 'open' : 'closed'}"
184
+ @click="${this.onClick}"
185
+ >
186
+ <slot name="header"></slot>
187
+ <squi-icon
188
+ icon="${this.icon}"
189
+ ?activeIcon="${this.active}"
190
+ class="small"
191
+ ></squi-icon>
192
+ </div>
193
+ <div class="content ${this.active ? 'open' : 'closed'}">
194
+ ${this.popup
195
+ ? html`<squi-icon
196
+ @click="${this.onClick}"
197
+ icon="closeLink"
198
+ class="link round close-link"
199
+ ></squi-icon>`
200
+ : ''}
201
+ <slot name="content"></slot>
202
+ </div> `;
203
+ }
204
+ }
@@ -0,0 +1,44 @@
1
+ import { html } from 'lit';
2
+ import '../pd-content.js';
3
+
4
+ export default {
5
+ title: 'PdContent',
6
+ component: 'pd-content',
7
+ argTypes: {
8
+ title: { control: 'text' },
9
+ counter: { control: 'number' },
10
+ textColor: { control: 'color' },
11
+ },
12
+ };
13
+
14
+ function Template({ title = 'Hello world', counter = 5, textColor, slot }) {
15
+ return html`
16
+ <pd-content
17
+ style="--pd-content-text-color: ${textColor || 'black'}"
18
+ .title=${title}
19
+ .counter=${counter}
20
+ >
21
+ ${slot}
22
+ </pd-content>
23
+ `;
24
+ }
25
+
26
+ export const Regular = Template.bind({});
27
+
28
+ export const CustomTitle = Template.bind({});
29
+ CustomTitle.args = {
30
+ title: 'My title',
31
+ };
32
+
33
+ export const CustomCounter = Template.bind({});
34
+ CustomCounter.args = {
35
+ counter: 123456,
36
+ };
37
+
38
+ export const SlottedContent = Template.bind({});
39
+ SlottedContent.args = {
40
+ slot: html`<p>Slotted content</p>`,
41
+ };
42
+ SlottedContent.argTypes = {
43
+ slot: { table: { disable: true } },
44
+ };
@@ -0,0 +1,32 @@
1
+ import { html } from 'lit';
2
+ import { fixture, expect } from '@open-wc/testing';
3
+
4
+ import '../pd-content.js';
5
+
6
+ describe('PdContent', () => {
7
+ it('has a default title "Hey there" and counter 5', async () => {
8
+ const el = await fixture(html`<pd-content></pd-content>`);
9
+
10
+ expect(el.title).to.equal('Hey there');
11
+ expect(el.counter).to.equal(5);
12
+ });
13
+
14
+ it('increases the counter on button click', async () => {
15
+ const el = await fixture(html`<pd-content></pd-content>`);
16
+ el.shadowRoot.querySelector('button').click();
17
+
18
+ expect(el.counter).to.equal(6);
19
+ });
20
+
21
+ it('can override the title via attribute', async () => {
22
+ const el = await fixture(html`<pd-content title="attribute title"></pd-content>`);
23
+
24
+ expect(el.title).to.equal('attribute title');
25
+ });
26
+
27
+ it('passes the a11y audit', async () => {
28
+ const el = await fixture(html`<pd-content></pd-content>`);
29
+
30
+ await expect(el).shadowDom.to.be.accessible();
31
+ });
32
+ });
@@ -0,0 +1,27 @@
1
+ // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
+
3
+ /** Use Hot Module replacement by adding --hmr to the start command */
4
+ const hmr = process.argv.includes('--hmr');
5
+
6
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
+ open: '/demo/',
8
+ /** Use regular watch mode if HMR is not enabled. */
9
+ watch: !hmr,
10
+ /** Resolve bare module imports */
11
+ nodeResolve: {
12
+ exportConditions: ['browser', 'development'],
13
+ },
14
+
15
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
+ // esbuildTarget: 'auto'
17
+
18
+ /** Set appIndex to enable SPA routing */
19
+ // appIndex: 'demo/index.html',
20
+
21
+ plugins: [
22
+ /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
+ // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
24
+ ],
25
+
26
+ // See documentation for all available options
27
+ });
@@ -0,0 +1,41 @@
1
+ // import { playwrightLauncher } from '@web/test-runner-playwright';
2
+
3
+ const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
4
+
5
+ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
+ /** Test files to run */
7
+ files: 'test/**/*.test.js',
8
+
9
+ /** Resolve bare module imports */
10
+ nodeResolve: {
11
+ exportConditions: ['browser', 'development'],
12
+ },
13
+
14
+ /** Filter out lit dev mode logs */
15
+ filterBrowserLogs(log) {
16
+ for (const arg of log.args) {
17
+ if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ },
23
+
24
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
+ // esbuildTarget: 'auto',
26
+
27
+ /** Amount of browsers to run concurrently */
28
+ // concurrentBrowsers: 2,
29
+
30
+ /** Amount of test files per browser to test concurrently */
31
+ // concurrency: 1,
32
+
33
+ /** Browsers to run tests on */
34
+ // browsers: [
35
+ // playwrightLauncher({ product: 'chromium' }),
36
+ // playwrightLauncher({ product: 'firefox' }),
37
+ // playwrightLauncher({ product: 'webkit' }),
38
+ // ],
39
+
40
+ // See documentation for all available options
41
+ });