@ng-zen/cli 19.0.0-alpha.2 → 19.0.0-alpha.4

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/README.md CHANGED
@@ -24,12 +24,6 @@ You can generate code using the ng-zen CLI.
24
24
  ng generate @ng-zen/cli:component
25
25
  ```
26
26
 
27
- #### Directives
28
-
29
- ```bash
30
- ng generate @ng-zen/cli:directive
31
- ```
32
-
33
27
  ## License
34
28
 
35
29
  This project is licensed under the BSD 2-Clause License. For more details, refer to the LICENSE file in the repository.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-zen/cli",
3
- "version": "19.0.0-alpha.2",
3
+ "version": "19.0.0-alpha.4",
4
4
  "description": "A blank schematics",
5
5
  "license": "BSD-2-Clause",
6
6
  "private": false,
@@ -1 +1 @@
1
- {"version":3,"file":"components-generator.js","sourceRoot":"","sources":["../../../../../projects/cli/src/schematics/components/components-generator.ts"],"names":[],"mappings":"","sourcesContent":["import { GeneratorSchemaBase } from '../../types';\n\nexport type ComponentType = 'avatar' | 'button';\n\nexport interface ComponentGeneratorSchema extends GeneratorSchemaBase {\n components: ComponentType[];\n}\n"]}
1
+ {"version":3,"file":"components-generator.js","sourceRoot":"","sources":["../../../../../projects/cli/src/schematics/components/components-generator.ts"],"names":[],"mappings":"","sourcesContent":["import { GeneratorSchemaBase } from '../../types';\n\nexport type ComponentType = 'avatar' | 'button' | 'checkbox' | 'input';\n\nexport interface ComponentGeneratorSchema extends GeneratorSchemaBase {\n components: ComponentType[];\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { GeneratorSchemaBase } from '../../types';
2
2
 
3
- export type ComponentType = 'avatar' | 'button';
3
+ export type ComponentType = 'avatar' | 'button' | 'checkbox' | 'input';
4
4
 
5
5
  export interface ComponentGeneratorSchema extends GeneratorSchemaBase {
6
6
  components: ComponentType[];
@@ -0,0 +1,69 @@
1
+ // Component Variables
2
+ $size: var(--zen-checkbox-size, 16px);
3
+ $border-radius: var(--zen-checkbox-border-radius, 6px);
4
+ $focus-shadow: var(--zen-checkbox-focus-shadow, 0 1px 4px hsla(0% 0% 60% / 20%) inset);
5
+
6
+ // Color Palette
7
+ $appearance: var(--zen-checkbox-appearance, hsl(0% 0% 10%));
8
+ $disabled-opacity: var(--zen-checkbox-disabled-opacity, 0.6);
9
+ $border: var(--zen-checkbox-border, 1px solid hsl(0% 0% 80%));
10
+ $error: var(--zen-error, hsl(0% 70% 50%));
11
+ $outline: var(--zen-outline, 1px solid hsl(0% 0% 60%));
12
+
13
+ // Animations
14
+ $transition-duration: var(--zen-transition-duration, 0.2s);
15
+
16
+ input {
17
+ position: absolute;
18
+ cursor: pointer;
19
+ opacity: 0;
20
+ height: 100%;
21
+ width: 100%;
22
+ padding: 0;
23
+ margin: 0;
24
+ top: 0;
25
+ left: 0;
26
+ }
27
+
28
+ :host {
29
+ background-color: white;
30
+ cursor: pointer;
31
+ border: $border;
32
+ border-radius: $border-radius;
33
+ height: $size;
34
+ width: $size;
35
+ position: relative;
36
+ transition:
37
+ background-color ease,
38
+ border-color ease;
39
+ transition-duration: $transition-duration;
40
+ user-select: none;
41
+ justify-content: center;
42
+ display: grid;
43
+ place-items: center;
44
+ font-size: small;
45
+ }
46
+
47
+ :host:has(input:checked) {
48
+ color: white;
49
+ background-color: $appearance;
50
+ border-color: $appearance;
51
+ }
52
+
53
+ :host:has(input[type='checkbox']:disabled) {
54
+ &,
55
+ input {
56
+ cursor: not-allowed;
57
+ }
58
+
59
+ opacity: $disabled-opacity;
60
+ }
61
+
62
+ :host:has(input:focus-visible) {
63
+ outline: $outline;
64
+ box-shadow: $focus-shadow;
65
+ }
66
+
67
+ :host:has(input:user-invalid) {
68
+ border-color: $error;
69
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { ZenCheckboxComponent } from './checkbox.component';
4
+
5
+ describe('ZenCheckboxComponent', () => {
6
+ let component: ZenCheckboxComponent;
7
+ let fixture: ComponentFixture<ZenCheckboxComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [ZenCheckboxComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(ZenCheckboxComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,97 @@
1
+ import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
2
+ import { booleanAttribute, ChangeDetectionStrategy, Component, forwardRef, input, model } from '@angular/core';
3
+
4
+ /**
5
+ * ZenCheckboxComponent is a reusable checkbox component designed to provide
6
+ * a consistent and customizable checkbox style across the application.
7
+ * It supports Angular forms integration and provides two-way data binding
8
+ * for boolean values.
9
+ *
10
+ * @example
11
+ * <zen-checkbox value="false" />
12
+ *
13
+ * @implements {ControlValueAccessor}
14
+ *
15
+ * @author Konrad Stępień
16
+ * @license {@link https://github.com/kstepien3/ng-zen?tab=BSD-2-Clause-1-ov-file|BSD-2-Clause}
17
+ * @see [GitHub](https://github.com/kstepien3/ng-zen)
18
+ */
19
+ @Component({
20
+ selector: 'zen-checkbox',
21
+ standalone: true,
22
+ template: `
23
+ <input
24
+ [attr.aria-disabled]="disabled()"
25
+ [attr.id]="id()"
26
+ [disabled]="disabled()"
27
+ [ngModel]="value()"
28
+ (ngModelChange)="onInputChange($event)"
29
+ #inputElement
30
+ type="checkbox"
31
+ />
32
+ @if (inputElement.indeterminate) {
33
+
34
+ } @else if (inputElement.checked) {
35
+
36
+ }
37
+ <!-- @else { ✕ } -->
38
+ `,
39
+ styleUrls: ['./checkbox.component.scss'],
40
+ changeDetection: ChangeDetectionStrategy.OnPush,
41
+ imports: [FormsModule],
42
+ providers: [
43
+ {
44
+ provide: NG_VALUE_ACCESSOR,
45
+ useExisting: forwardRef(() => ZenCheckboxComponent),
46
+ multi: true,
47
+ },
48
+ ],
49
+ host: {
50
+ '(blur)': 'onTouched()',
51
+ },
52
+ })
53
+ export class ZenCheckboxComponent implements ControlValueAccessor {
54
+ /** Holds the current checkbox value. */
55
+ readonly value = model(false);
56
+ /** Determines if the checkbox is disabled. */
57
+ readonly disabled = model(false);
58
+ /** Determines if the input is required.*/
59
+ readonly required = input(false, { transform: booleanAttribute });
60
+ /** Sets the HTML id attribute for the checkbox element. */
61
+ readonly id = input<string>();
62
+
63
+ /** @ignore */
64
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
65
+ onChange: (value: boolean) => void = () => {};
66
+ /** @ignore */
67
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
68
+ onTouched: () => void = () => {};
69
+
70
+ /** @ignore */
71
+ writeValue(value: boolean): void {
72
+ this.value.set(value);
73
+ }
74
+
75
+ /** @ignore */
76
+ registerOnChange(fn: (value: boolean) => void): void {
77
+ this.onChange = fn;
78
+ }
79
+
80
+ /** @ignore */
81
+ registerOnTouched(fn: () => void): void {
82
+ this.onTouched = fn;
83
+ }
84
+
85
+ /** @ignore */
86
+ setDisabledState(isDisabled: boolean): void {
87
+ this.disabled.set(isDisabled);
88
+ }
89
+
90
+ /** Handles checkbox change event */
91
+ onInputChange(value: boolean): void {
92
+ if (this.disabled()) return;
93
+
94
+ this.value.set(value);
95
+ this.onChange(value);
96
+ }
97
+ }
@@ -0,0 +1,46 @@
1
+ import { Meta, StoryObj } from '@storybook/angular';
2
+ import { ZenCheckboxComponent } from './checkbox.component';
3
+
4
+ export default {
5
+ title: 'Components/Checkbox',
6
+ component: ZenCheckboxComponent,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ value: { control: 'boolean' },
10
+ disabled: { control: 'boolean' },
11
+ required: { control: 'boolean' },
12
+ id: { control: 'text' },
13
+ },
14
+ args: {
15
+ value: false,
16
+ disabled: false,
17
+ required: false,
18
+ id: '',
19
+ },
20
+ } satisfies Meta<ZenCheckboxComponent>;
21
+
22
+ type Story = StoryObj<ZenCheckboxComponent>;
23
+
24
+ export const Default: Story = {
25
+ render: args => ({
26
+ props: { ...args },
27
+ template: `
28
+ <zen-checkbox
29
+ [disabled]="${args.disabled}"
30
+ [value]="${args.value}"
31
+ ${args.id ? 'id="' + args.id + '"' : ''}
32
+ ${args.required ? 'required' : ''}
33
+ />`,
34
+ }),
35
+ };
36
+
37
+ export const WithLabel: Story = {
38
+ render: () => ({
39
+ template: `
40
+ <div style="display: flex; align-items: center; gap: 0.25rem">
41
+ <zen-checkbox id="label-example"/>
42
+ <label for="label-example"> With label </label>
43
+ </div>
44
+ `,
45
+ }),
46
+ };
@@ -0,0 +1 @@
1
+ export * from './checkbox.component';
@@ -0,0 +1 @@
1
+ export * from './input.component';
@@ -0,0 +1,33 @@
1
+ // Component Variables
2
+ $border: var(--zen-input-border, 1px solid hsl(0% 0% 80%));
3
+ $border-radius: var(--zen-input-border-radius, 8px);
4
+ $padding: var(--zen-input-padding, 0.5rem 1rem);
5
+ $focus-shadow: var(--zen-input-focus-shadow, 0 1px 4px hsla(0% 0% 60% / 20%) inset);
6
+ $placeholder-color: var(--zen-input-placeholder-color, hsl(0% 0% 60%));
7
+
8
+ // Color Palette
9
+ $outline: var(--zen-outline, 1px solid hsl(0% 0% 60%));
10
+ $error: var(--zen-error, hsl(0% 70% 50%));
11
+
12
+ input {
13
+ border: $border;
14
+ border-radius: $border-radius;
15
+ padding: $padding;
16
+
17
+ &:disabled {
18
+ opacity: 0.6;
19
+ }
20
+
21
+ &:focus-visible {
22
+ outline: $outline;
23
+ box-shadow: $focus-shadow;
24
+ }
25
+
26
+ &:user-invalid {
27
+ border-color: $error;
28
+ }
29
+
30
+ &::placeholder {
31
+ color: $placeholder-color;
32
+ }
33
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { ZenInputComponent } from './input.component';
4
+
5
+ describe('InputComponent', () => {
6
+ let component: ZenInputComponent;
7
+ let fixture: ComponentFixture<ZenInputComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [ZenInputComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(ZenInputComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,88 @@
1
+ import { booleanAttribute, ChangeDetectionStrategy, Component, forwardRef, input, model } from '@angular/core';
2
+ import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
3
+
4
+ /**
5
+ * ZenInputComponent is a reusable text input component designed to provide
6
+ * a consistent and customizable input style across the application.
7
+ * It supports Angular forms integration and provides two-way data binding.
8
+ *
9
+ * @example
10
+ * <zen-input value="string" />
11
+ *
12
+ * @implements {ControlValueAccessor}
13
+ *
14
+ * @author Konrad Stępień
15
+ * @license {@link https://github.com/kstepien3/ng-zen?tab=BSD-2-Clause-1-ov-file|BSD-2-Clause}
16
+ * @see [GitHub](https://github.com/kstepien3/ng-zen)
17
+ */
18
+ @Component({
19
+ selector: 'zen-input',
20
+ standalone: true,
21
+ template: `
22
+ <input
23
+ [attr.id]="id()"
24
+ [attr.placeholder]="placeholder()"
25
+ [attr.required]="required()"
26
+ [disabled]="disabled()"
27
+ [ngModel]="value()"
28
+ [value]="value()"
29
+ (blur)="onTouched()"
30
+ (ngModelChange)="onInputChange($event)"
31
+ />
32
+ `,
33
+ styleUrls: ['./input.component.scss'],
34
+ changeDetection: ChangeDetectionStrategy.OnPush,
35
+ providers: [
36
+ {
37
+ provide: NG_VALUE_ACCESSOR,
38
+ useExisting: forwardRef(() => ZenInputComponent),
39
+ multi: true,
40
+ },
41
+ ],
42
+ imports: [FormsModule],
43
+ })
44
+ export class ZenInputComponent implements ControlValueAccessor {
45
+ /** Holds the current input value. */
46
+ readonly value = model('');
47
+ /** Determines if the input is disabled. */
48
+ readonly disabled = model(false);
49
+ /** Determines if the input is required.*/
50
+ readonly required = input(false, { transform: booleanAttribute });
51
+ /** Sets the HTML id attribute for the input element.*/
52
+ readonly id = input<string>();
53
+ /** Provides a hint or example text that will be displayed */
54
+ readonly placeholder = input<string>();
55
+
56
+ /** @ignore */
57
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
58
+ onChange: (value: string) => void = () => {};
59
+ /** @ignore */
60
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
61
+ onTouched: () => void = () => {};
62
+
63
+ /** @ignore */
64
+ writeValue(value: string): void {
65
+ this.value.set(value);
66
+ }
67
+ /** @ignore */
68
+ registerOnChange(fn: (value: string) => void): void {
69
+ this.onChange = fn;
70
+ }
71
+ /** @ignore */
72
+ registerOnTouched(fn: () => void): void {
73
+ this.onTouched = fn;
74
+ }
75
+
76
+ /** @ignore */
77
+ setDisabledState(isDisabled: boolean): void {
78
+ this.disabled.set(isDisabled);
79
+ }
80
+
81
+ /** Handles input change event */
82
+ onInputChange(value: string): void {
83
+ if (this.disabled()) return;
84
+
85
+ this.value.set(value);
86
+ this.onChange(value);
87
+ }
88
+ }
@@ -0,0 +1,49 @@
1
+ import { Meta, StoryObj } from '@storybook/angular';
2
+ import { ZenInputComponent } from './input.component';
3
+
4
+ export default {
5
+ title: 'Components/Input',
6
+ component: ZenInputComponent,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ value: { control: 'text' },
10
+ placeholder: { control: 'text' },
11
+ disabled: { control: 'boolean' },
12
+ required: { control: 'boolean' },
13
+ id: { control: 'text' },
14
+ },
15
+ args: {
16
+ value: '',
17
+ placeholder: '',
18
+ disabled: false,
19
+ required: false,
20
+ id: '',
21
+ },
22
+ } satisfies Meta<ZenInputComponent>;
23
+
24
+ type Story = StoryObj<ZenInputComponent>;
25
+
26
+ export const Default: Story = {
27
+ render: args => ({
28
+ props: { ...args },
29
+ template: `
30
+ <zen-input
31
+ [disabled]="${args.disabled}"
32
+ [value]="'${args.value}'"
33
+ ${args.id ? 'id="' + args.id + '"' : ''}
34
+ ${args.placeholder ? 'placeholder="' + args.placeholder + '"' : ''}
35
+ ${args.required ? 'required' : ''}
36
+ />`,
37
+ }),
38
+ };
39
+
40
+ export const WithLabel: Story = {
41
+ render: () => ({
42
+ template: `
43
+ <div style="display: flex; flex-direction: column">
44
+ <label for="label-example"> With label </label>
45
+ <zen-input id="label-example"/>
46
+ </div>
47
+ `,
48
+ }),
49
+ };
@@ -10,7 +10,7 @@
10
10
  "type": "array",
11
11
  "items": {
12
12
  "type": "string",
13
- "enum": ["avatar", "button"]
13
+ "enum": ["avatar", "button", "checkbox", "input"]
14
14
  },
15
15
  "multiselect": true,
16
16
  "x-prompt": "Which component should be generated?"