edu-webcomponents 1.17.0 → 1.19.7

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/package.json CHANGED
@@ -1,73 +1,73 @@
1
- {
2
- "name": "edu-webcomponents",
3
- "description": "Webcomponent edu-webcomponents following open-wc recommendations",
4
- "keywords": [
5
- "web components library",
6
- "web components catalog",
7
- "webcomponents library",
8
- "webcomponents catalog",
9
- "web components",
10
- "webcomponents"
11
- ],
12
- "license": "MIT",
13
- "author": "edu-webcomponents",
14
- "version": "1.17.0",
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/eduardocruzpalacios/edu-webcomponents"
18
- },
19
- "type": "module",
20
- "main": "index.js",
21
- "module": "index.js",
22
- "exports": {
23
- ".": "./index.js"
24
- },
25
- "scripts": {
26
- "analyze": "cem analyze --litelement",
27
- "start": "web-dev-server",
28
- "lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
29
- "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
30
- "test": "web-test-runner --coverage",
31
- "test:watch": "web-test-runner --watch",
32
- "prepare": "husky",
33
- "storybook": "storybook dev -p 6006",
34
- "build-storybook": "storybook build"
35
- },
36
- "dependencies": {
37
- "lit": "^2.8.0"
38
- },
39
- "devDependencies": {
40
- "@chromatic-com/storybook": "^1.5.0",
41
- "@custom-elements-manifest/analyzer": "^0.10.2",
42
- "@open-wc/eslint-config": "^9.2.2",
43
- "@open-wc/testing": "^3.2.2",
44
- "@storybook/addon-essentials": "^8.1.10",
45
- "@storybook/addon-links": "^8.1.10",
46
- "@storybook/addon-webpack5-compiler-swc": "^1.0.4",
47
- "@storybook/blocks": "^8.1.10",
48
- "@storybook/test": "^8.1.10",
49
- "@storybook/web-components": "^8.1.10",
50
- "@storybook/web-components-webpack5": "^8.1.10",
51
- "@web/dev-server": "^0.4.5",
52
- "@web/test-runner": "^0.18.2",
53
- "eslint": "^8.57.0",
54
- "eslint-config-prettier": "^8.10.0",
55
- "eslint-plugin-storybook": "^0.8.0",
56
- "husky": "^9.0.11",
57
- "lint-staged": "^10.5.4",
58
- "prettier": "^2.8.8",
59
- "storybook": "^8.1.10"
60
- },
61
- "customElements": "custom-elements.json",
62
- "eslintConfig": {
63
- "extends": [
64
- "@open-wc",
65
- "prettier",
66
- "plugin:storybook/recommended"
67
- ]
68
- },
69
- "prettier": {
70
- "singleQuote": true,
71
- "arrowParens": "avoid"
72
- }
1
+ {
2
+ "name": "edu-webcomponents",
3
+ "description": "Webcomponent edu-webcomponents following open-wc recommendations",
4
+ "keywords": [
5
+ "web components library",
6
+ "web components catalog",
7
+ "webcomponents library",
8
+ "webcomponents catalog",
9
+ "web components",
10
+ "webcomponents"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "edu-webcomponents",
14
+ "version": "1.19.7",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/eduardocruzpalacios/edu-webcomponents"
18
+ },
19
+ "type": "module",
20
+ "main": "index.js",
21
+ "module": "index.js",
22
+ "exports": {
23
+ ".": "./index.js"
24
+ },
25
+ "scripts": {
26
+ "analyze": "cem analyze --litelement",
27
+ "start": "web-dev-server",
28
+ "lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
29
+ "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
30
+ "test": "web-test-runner --coverage",
31
+ "test:watch": "web-test-runner --watch",
32
+ "prepare": "husky",
33
+ "storybook": "storybook dev -p 6006",
34
+ "build-storybook": "storybook build"
35
+ },
36
+ "dependencies": {
37
+ "lit": "^2.8.0"
38
+ },
39
+ "devDependencies": {
40
+ "@chromatic-com/storybook": "^1.5.0",
41
+ "@custom-elements-manifest/analyzer": "^0.10.2",
42
+ "@open-wc/eslint-config": "^9.2.2",
43
+ "@open-wc/testing": "^3.2.2",
44
+ "@storybook/addon-essentials": "^8.1.10",
45
+ "@storybook/addon-links": "^8.1.10",
46
+ "@storybook/addon-webpack5-compiler-swc": "^1.0.4",
47
+ "@storybook/blocks": "^8.1.10",
48
+ "@storybook/test": "^8.1.10",
49
+ "@storybook/web-components": "^8.1.10",
50
+ "@storybook/web-components-webpack5": "^8.1.10",
51
+ "@web/dev-server": "^0.4.5",
52
+ "@web/test-runner": "^0.18.2",
53
+ "eslint": "^8.57.0",
54
+ "eslint-config-prettier": "^8.10.0",
55
+ "eslint-plugin-storybook": "^0.8.0",
56
+ "husky": "^9.0.11",
57
+ "lint-staged": "^10.5.4",
58
+ "prettier": "^2.8.8",
59
+ "storybook": "^8.1.10"
60
+ },
61
+ "customElements": "custom-elements.json",
62
+ "eslintConfig": {
63
+ "extends": [
64
+ "@open-wc",
65
+ "prettier",
66
+ "plugin:storybook/recommended"
67
+ ]
68
+ },
69
+ "prettier": {
70
+ "singleQuote": true,
71
+ "arrowParens": "avoid"
72
+ }
73
73
  }
package/src/EduButton.js CHANGED
@@ -1,57 +1,61 @@
1
- import { html, css, LitElement } from 'lit';
2
-
3
- export class EduButton extends LitElement {
4
- static styles = css`
5
- :host {
6
- display: block;
7
- }
8
-
9
- button {
10
- padding: 0.5rem 1rem;
11
- font-size: 1rem;
12
- border: none;
13
- border-radius: 4px;
14
- background-color: #007acc;
15
- color: white;
16
- cursor: pointer;
17
- transition: background-color 0.2s ease-in-out;
18
- }
19
-
20
- button:hover:not(:disabled) {
21
- background-color: #005fa3;
22
- }
23
-
24
- button:disabled {
25
- background-color: #ccc;
26
- cursor: not-allowed;
27
- }
28
- `;
29
-
30
- static properties = {
31
- text: { type: String },
32
- type: { type: String },
33
- ariaLabel: { type: String, attribute: 'aria-label' },
34
- disabled: { type: Boolean, reflect: true },
35
- };
36
-
37
- constructor() {
38
- super();
39
- this.text = 'Default text';
40
- this.type = 'button';
41
- this.ariaLabel = this.text;
42
- }
43
-
44
- render() {
45
- return html`
46
- <button
47
- type=${this.type}
48
- aria-label=${this.ariaLabel}
49
- ?disabled=${this.disabled}
50
- >
51
- ${this.text}
52
- </button>
53
- `;
54
- }
55
- }
56
-
57
- window.customElements.define('edu-button', EduButton);
1
+ import { html, css, LitElement } from 'lit';
2
+ import { colorsConstants } from './stylesConstants.js';
3
+
4
+ export class EduButton extends LitElement {
5
+ static styles = [
6
+ colorsConstants,
7
+ css`
8
+ :host {
9
+ display: block;
10
+ }
11
+
12
+ button {
13
+ padding: 0.5rem 1rem;
14
+ font-size: 1rem;
15
+ border: none;
16
+ border-radius: 4px;
17
+ background-color: var(--primary);
18
+ color: var(--primaryForeground);
19
+ cursor: pointer;
20
+ transition: background-color 0.2s ease-in-out;
21
+ }
22
+
23
+ button:hover:not(:disabled) {
24
+ background-color: var(--primaryHover);
25
+ }
26
+
27
+ button:disabled {
28
+ background-color: var(--disabled);
29
+ cursor: not-allowed;
30
+ }
31
+ `,
32
+ ];
33
+
34
+ static properties = {
35
+ text: { type: String },
36
+ type: { type: String },
37
+ ariaLabel: { type: String, attribute: 'aria-label' },
38
+ disabled: { type: Boolean, reflect: true },
39
+ };
40
+
41
+ constructor() {
42
+ super();
43
+ this.text = 'Default text';
44
+ this.type = 'button';
45
+ this.ariaLabel = this.text;
46
+ }
47
+
48
+ render() {
49
+ return html`
50
+ <button
51
+ type=${this.type}
52
+ aria-label=${this.ariaLabel}
53
+ ?disabled=${this.disabled}
54
+ >
55
+ ${this.text}
56
+ </button>
57
+ `;
58
+ }
59
+ }
60
+
61
+ window.customElements.define('edu-button', EduButton);
@@ -0,0 +1,78 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { colorsConstants } from './stylesConstants.js';
3
+
4
+ export class EduProgressBar extends LitElement {
5
+ static properties = {
6
+ value: { type: Number },
7
+ max: { type: Number },
8
+ showLabel: { type: Boolean },
9
+ progressbarName: { type: String },
10
+ };
11
+
12
+ static styles = [
13
+ colorsConstants,
14
+ css`
15
+ :host {
16
+ display: block;
17
+ width: 100%;
18
+ }
19
+ .bar-container {
20
+ position: relative;
21
+ width: 100%;
22
+ height: 20px;
23
+ background-color: var(--greyLight);
24
+ border-radius: 10px;
25
+ overflow: hidden;
26
+ }
27
+ .bar-fill {
28
+ height: 100%;
29
+ background-color: var(--primary);
30
+ transition: width 0.3s ease;
31
+ }
32
+ .label {
33
+ position: absolute;
34
+ top: 0;
35
+ left: 50%;
36
+ transform: translate(-50%, 0);
37
+ height: 100%;
38
+ display: flex;
39
+ align-items: center;
40
+ justify-content: center;
41
+ font-size: 12px;
42
+ font-weight: bold;
43
+ color: var(--blackLight);
44
+ pointer-events: none;
45
+ }
46
+ `,
47
+ ];
48
+
49
+ constructor() {
50
+ super();
51
+ this.value = 0;
52
+ this.max = 100;
53
+ this.progressbarName = 'Progress bar';
54
+ }
55
+
56
+ render() {
57
+ const safeMax = this.max > 0 ? this.max : 100;
58
+ const safeValue = Math.max(0, this.value);
59
+ const percentage = Math.min(100, (safeValue / safeMax) * 100);
60
+ const label = `${Math.round(percentage)}%`;
61
+
62
+ return html`
63
+ <div
64
+ class="bar-container"
65
+ role="progressbar"
66
+ aria-valuemin="0"
67
+ aria-valuemax="${safeMax}"
68
+ aria-valuenow="${Math.min(safeValue, safeMax)}"
69
+ aria-label="${this.progressbarName}"
70
+ >
71
+ <div class="bar-fill" style="width: ${percentage}%"></div>
72
+ ${this.showLabel ? html`<div class="label">${label}</div>` : null}
73
+ </div>
74
+ `;
75
+ }
76
+ }
77
+
78
+ customElements.define('edu-progress-bar', EduProgressBar);
@@ -0,0 +1,126 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { colorsConstants } from './stylesConstants.js';
3
+
4
+ const POSITION = {
5
+ BOTTOM: 'bottom',
6
+ TOP: 'top',
7
+ LEFT: 'left',
8
+ RIGHT: 'right',
9
+ };
10
+
11
+ function getPositions() {
12
+ return Object.values(POSITION);
13
+ }
14
+
15
+ function isPositionValid(position) {
16
+ return getPositions().includes(position.toLowerCase());
17
+ }
18
+
19
+ export class EduTooltip extends LitElement {
20
+ static properties = {
21
+ text: { type: String },
22
+ position: { type: String },
23
+ visible: { type: Boolean, reflect: true },
24
+ };
25
+
26
+ constructor() {
27
+ super();
28
+ this._tooltipId = `tooltip-${Math.random().toString(36).slice(2)}`;
29
+ }
30
+
31
+ updated(changedProperties) {
32
+ if (changedProperties.has('position')) {
33
+ if (!isPositionValid(this.position)) {
34
+ this.position = POSITION.BOTTOM;
35
+ }
36
+ }
37
+ }
38
+
39
+ static styles = [
40
+ colorsConstants,
41
+ css`
42
+ :host {
43
+ position: relative;
44
+ display: inline-block;
45
+ }
46
+
47
+ .tooltip {
48
+ position: absolute;
49
+ background-color: var(--blackLight);
50
+ color: var(--primaryForeground);
51
+ padding: 6px 10px;
52
+ border-radius: 4px;
53
+ font-size: 12px;
54
+ white-space: nowrap;
55
+ z-index: 10;
56
+ opacity: 0;
57
+ transition: opacity 0.2s;
58
+ pointer-events: none;
59
+ }
60
+
61
+ :host([visible]) .tooltip {
62
+ opacity: 1;
63
+ }
64
+
65
+ .top {
66
+ bottom: 100%;
67
+ left: 50%;
68
+ transform: translateX(-50%) translateY(-5px);
69
+ }
70
+
71
+ .right {
72
+ top: 50%;
73
+ left: 100%;
74
+ transform: translateX(5px) translateY(-50%);
75
+ }
76
+
77
+ .bottom {
78
+ top: 100%;
79
+ left: 50%;
80
+ transform: translateX(-50%) translateY(5px);
81
+ }
82
+
83
+ .left {
84
+ top: 50%;
85
+ left: auto;
86
+ right: 100%;
87
+ transform: translateX(-5px) translateY(-50%);
88
+ }
89
+ `,
90
+ ];
91
+
92
+ render() {
93
+ const positionClass = this.position
94
+ ? this.position.toLocaleLowerCase()
95
+ : POSITION.BOTTOM;
96
+ return html`
97
+ <span
98
+ tabindex="0"
99
+ aria-describedby=${this._tooltipId}
100
+ @mouseenter=${this._show}
101
+ @mouseleave=${this._hide}
102
+ @focus=${this._show}
103
+ @blur=${this._hide}
104
+ >
105
+ <slot></slot>
106
+ </span>
107
+ <div
108
+ id=${this._tooltipId}
109
+ class="tooltip ${positionClass}"
110
+ role="tooltip"
111
+ >
112
+ ${this.text}
113
+ </div>
114
+ `;
115
+ }
116
+
117
+ _show() {
118
+ this.visible = true;
119
+ }
120
+
121
+ _hide() {
122
+ this.visible = false;
123
+ }
124
+ }
125
+
126
+ customElements.define('edu-tooltip', EduTooltip);
@@ -0,0 +1,102 @@
1
+ import { html } from 'lit';
2
+ import '../EduProgressBar.js';
3
+
4
+ export default {
5
+ title: 'Edu web components/EduProgressBar',
6
+ tags: ['autodocs'],
7
+ render: ({ value, max, showLabel }) =>
8
+ html`<edu-progress-bar
9
+ .value=${value}
10
+ .max=${max}
11
+ ?showLabel=${showLabel}
12
+ ></edu-progress-bar>`,
13
+ argTypes: {
14
+ value: {
15
+ value: 'number',
16
+ description: 'Sets the percentage to which the progress bar is filled in',
17
+ name: 'value',
18
+ },
19
+ max: {
20
+ value: 'number',
21
+ description: 'Sets the value to which the percentage is calculated',
22
+ name: 'max',
23
+ },
24
+ showLabel: {
25
+ value: 'boolean',
26
+ description: 'Shows label of percentage filled in',
27
+ name: 'showLabel',
28
+ },
29
+ },
30
+ args: {
31
+ value: 0,
32
+ max: 100,
33
+ showLabel: false,
34
+ },
35
+ };
36
+
37
+ export const EduProgressBarDefault = {
38
+ args: {},
39
+ };
40
+
41
+ export const EduProgressBar25 = {
42
+ args: {
43
+ value: 25,
44
+ },
45
+ };
46
+ export const EduProgressBar50 = {
47
+ args: {
48
+ value: 50,
49
+ },
50
+ };
51
+ export const EduProgressBar50WithMaxChanged = {
52
+ args: {
53
+ value: 25,
54
+ max: 50,
55
+ },
56
+ };
57
+ export const EduProgressBar75 = {
58
+ args: {
59
+ value: 75,
60
+ },
61
+ };
62
+ export const EduProgressBar100 = {
63
+ args: {
64
+ value: 100,
65
+ },
66
+ };
67
+
68
+ export const EduProgressBarWithLabel = {
69
+ args: { showLabel: true },
70
+ };
71
+
72
+ export const EduProgressBar25WithLabel = {
73
+ args: {
74
+ value: 25,
75
+ showLabel: true,
76
+ },
77
+ };
78
+ export const EduProgressBar50WithLabel = {
79
+ args: {
80
+ value: 50,
81
+ showLabel: true,
82
+ },
83
+ };
84
+ export const EduProgressBar50WithLabelAndMaxChanged = {
85
+ args: {
86
+ value: 25,
87
+ max: 50,
88
+ showLabel: true,
89
+ },
90
+ };
91
+ export const EduProgressBar75WithLabel = {
92
+ args: {
93
+ value: 75,
94
+ showLabel: true,
95
+ },
96
+ };
97
+ export const EduProgressBar100WithLabel = {
98
+ args: {
99
+ value: 100,
100
+ showLabel: true,
101
+ },
102
+ };
@@ -0,0 +1,68 @@
1
+ import { html } from 'lit';
2
+ import '../EduTooltip.js';
3
+
4
+ export default {
5
+ title: 'Edu web components/EduTooltip',
6
+ tags: ['autodocs'],
7
+ render: ({ text, position }) =>
8
+ html`<edu-tooltip .text=${text} .position=${position}
9
+ ><p>Hello, place the mouse over this text</p></edu-tooltip
10
+ >`,
11
+ argTypes: {
12
+ text: {
13
+ control: 'text',
14
+ description: 'Overwritten button text',
15
+ name: 'text',
16
+ },
17
+ position: {
18
+ control: 'text',
19
+ description:
20
+ 'Position of the tooltip respect to the element making it visible: top / bottom / left / right',
21
+ name: 'position',
22
+ },
23
+ },
24
+ args: {
25
+ text: 'Custom text',
26
+ position: '',
27
+ },
28
+ };
29
+
30
+ export const EduTooltipDefaultPositionBottom = {
31
+ args: {},
32
+ };
33
+
34
+ export const EduTooltipInvalidPositionPropBottom = {
35
+ args: {
36
+ position: 'Edu',
37
+ },
38
+ };
39
+
40
+ export const EduTooltipPositionBottom = {
41
+ args: {
42
+ position: 'bottom',
43
+ },
44
+ };
45
+
46
+ export const EduTooltipPositionTop = {
47
+ args: {
48
+ position: 'top',
49
+ },
50
+ };
51
+
52
+ export const EduTooltipPositionRight = {
53
+ args: {
54
+ position: 'right',
55
+ },
56
+ };
57
+
58
+ export const EduTooltipPositionLeft = {
59
+ args: {
60
+ position: 'left',
61
+ },
62
+ };
63
+
64
+ export const EduTooltipPositionLeftCaseInsensitive = {
65
+ args: {
66
+ position: 'LEFT',
67
+ },
68
+ };
@@ -0,0 +1,15 @@
1
+ import { css } from 'lit';
2
+
3
+ export const colorsConstants = css`
4
+ :host {
5
+ --primary: #007acc;
6
+ --primaryHover: #005fa3;
7
+ --primaryForeground: #fff;
8
+
9
+ --blackLight: #333;
10
+
11
+ --greyLight: #eee;
12
+
13
+ --disabled: #ccc;
14
+ }
15
+ `;