@ng-zen/cli 19.0.0-alpha.3 → 19.0.0-alpha.5

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-zen/cli",
3
- "version": "19.0.0-alpha.3",
3
+ "version": "19.0.0-alpha.5",
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' | 'input';\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' | 'textarea';\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' | 'input';
3
+ export type ComponentType = 'avatar' | 'button' | 'checkbox' | 'input' | 'textarea';
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';
@@ -1,8 +1,13 @@
1
- $border: var(--zen-input-border, 1px solid #cbcbcb);
1
+ // Component Variables
2
+ $border: var(--zen-input-border, 1px solid hsl(0% 0% 80%));
2
3
  $border-radius: var(--zen-input-border-radius, 8px);
3
4
  $padding: var(--zen-input-padding, 0.5rem 1rem);
4
- $outline: var(--zen-outline, 1px solid #999);
5
- $border-invalid: var(--zen-error, #dc2626);
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%));
6
11
 
7
12
  input {
8
13
  border: $border;
@@ -15,14 +20,14 @@ input {
15
20
 
16
21
  &:focus-visible {
17
22
  outline: $outline;
18
- box-shadow: 0 1px 4px #9999993f inset;
23
+ box-shadow: $focus-shadow;
19
24
  }
20
25
 
21
26
  &:user-invalid {
22
- border-color: $border-invalid;
27
+ border-color: $error;
23
28
  }
24
29
 
25
30
  &::placeholder {
26
- color: #999;
31
+ color: $placeholder-color;
27
32
  }
28
33
  }
@@ -1,5 +1,5 @@
1
1
  import { booleanAttribute, ChangeDetectionStrategy, Component, forwardRef, input, model } from '@angular/core';
2
- import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
2
+ import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
3
3
 
4
4
  /**
5
5
  * ZenInputComponent is a reusable text input component designed to provide
@@ -12,8 +12,8 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
12
12
  * @implements {ControlValueAccessor}
13
13
  *
14
14
  * @author Konrad Stępień
15
- * @license {@link https://github.com/Kordrad/ng-zen?tab=BSD-2-Clause-1-ov-file|BSD-2-Clause}
16
- * @see [GitHub](https://github.com/Kordrad/ng-zen)
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
17
  */
18
18
  @Component({
19
19
  selector: 'zen-input',
@@ -24,12 +24,14 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
24
24
  [attr.placeholder]="placeholder()"
25
25
  [attr.required]="required()"
26
26
  [disabled]="disabled()"
27
+ [ngModel]="value()"
27
28
  [value]="value()"
28
29
  (blur)="onTouched()"
29
- (input)="onInputChange($event)"
30
+ (ngModelChange)="onInputChange($event)"
30
31
  />
31
32
  `,
32
33
  styleUrls: ['./input.component.scss'],
34
+ changeDetection: ChangeDetectionStrategy.OnPush,
33
35
  providers: [
34
36
  {
35
37
  provide: NG_VALUE_ACCESSOR,
@@ -37,7 +39,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
37
39
  multi: true,
38
40
  },
39
41
  ],
40
- changeDetection: ChangeDetectionStrategy.OnPush,
42
+ imports: [FormsModule],
41
43
  })
42
44
  export class ZenInputComponent implements ControlValueAccessor {
43
45
  /** Holds the current input value. */
@@ -76,10 +78,11 @@ export class ZenInputComponent implements ControlValueAccessor {
76
78
  this.disabled.set(isDisabled);
77
79
  }
78
80
 
79
- /** @ignore */
80
- onInputChange(event: Event): void {
81
- const newValue = (event.target as HTMLInputElement).value;
82
- this.value.set(newValue);
83
- this.onChange(newValue);
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);
84
87
  }
85
88
  }
@@ -10,12 +10,14 @@ export default {
10
10
  placeholder: { control: 'text' },
11
11
  disabled: { control: 'boolean' },
12
12
  required: { control: 'boolean' },
13
+ id: { control: 'text' },
13
14
  },
14
15
  args: {
15
16
  value: '',
16
17
  placeholder: '',
17
18
  disabled: false,
18
19
  required: false,
20
+ id: '',
19
21
  },
20
22
  } satisfies Meta<ZenInputComponent>;
21
23
 
@@ -28,7 +30,8 @@ export const Default: Story = {
28
30
  <zen-input
29
31
  [disabled]="${args.disabled}"
30
32
  [value]="'${args.value}'"
31
- [placeholder]="${args.placeholder}"
33
+ ${args.id ? 'id="' + args.id + '"' : ''}
34
+ ${args.placeholder ? 'placeholder="' + args.placeholder + '"' : ''}
32
35
  ${args.required ? 'required' : ''}
33
36
  />`,
34
37
  }),
@@ -0,0 +1 @@
1
+ export * from './textarea.component';
@@ -0,0 +1,38 @@
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
+ :host {
13
+ border: $border;
14
+ border-radius: $border-radius;
15
+ padding: $padding;
16
+
17
+ &[autoresize] {
18
+ field-sizing: content;
19
+ resize: none;
20
+ }
21
+
22
+ &:disabled {
23
+ opacity: 0.6;
24
+ }
25
+
26
+ &:focus-visible {
27
+ outline: $outline;
28
+ box-shadow: $focus-shadow;
29
+ }
30
+
31
+ &:user-invalid {
32
+ border-color: $error;
33
+ }
34
+
35
+ &::placeholder {
36
+ color: $placeholder-color;
37
+ }
38
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { ZenTextareaComponent } from './textarea.component';
4
+
5
+ describe('ZenTextareaComponent', () => {
6
+ let component: ZenTextareaComponent;
7
+ let fixture: ComponentFixture<ZenTextareaComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [ZenTextareaComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(ZenTextareaComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it('should create', () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,25 @@
1
+ import { ChangeDetectionStrategy, Component } from '@angular/core';
2
+
3
+ /**
4
+ * ZenTextareaComponent is a reusable textarea component designed to provide
5
+ * a consistent and customizable textarea style across the application.
6
+ * It supports Angular forms integration and provides two-way data binding.
7
+ *
8
+ * @example
9
+ * <textarea zen-textarea></textarea>
10
+ *
11
+ * @author Konrad Stępień
12
+ * @license {@link https://github.com/kstepien3/ng-zen?tab=BSD-2-Clause-1-ov-file|BSD-2-Clause}
13
+ * @see [GitHub](https://github.com/kstepien3/ng-zen)
14
+ */
15
+ @Component({
16
+ // eslint-disable-next-line @angular-eslint/component-selector
17
+ selector: 'textarea[zen-textarea], textarea[zen-textarea][autoresize]',
18
+ standalone: true,
19
+ template: `
20
+ <ng-content />
21
+ `,
22
+ styleUrls: ['./textarea.component.scss'],
23
+ changeDetection: ChangeDetectionStrategy.OnPush,
24
+ })
25
+ export class ZenTextareaComponent {}
@@ -0,0 +1,65 @@
1
+ import { Meta, StoryObj } from '@storybook/angular';
2
+ import { ZenTextareaComponent } from './textarea.component';
3
+
4
+ interface StoryParams {
5
+ value: string;
6
+ placeholder: string;
7
+ required: boolean;
8
+ autoresize: boolean;
9
+ disabled: boolean;
10
+ }
11
+
12
+ export default {
13
+ title: 'Components/Textarea',
14
+ component: ZenTextareaComponent,
15
+ tags: ['autodocs'],
16
+ args: {
17
+ value: '',
18
+ autoresize: false,
19
+ placeholder: 'ZenTextareaComponent',
20
+ required: false,
21
+ disabled: false,
22
+ },
23
+ argTypes: {
24
+ value: { control: 'text' },
25
+ autoresize: { control: 'boolean' },
26
+ placeholder: { control: 'text' },
27
+ required: { control: 'boolean' },
28
+ disabled: { control: 'boolean' },
29
+ },
30
+ } satisfies Meta<ZenTextareaComponent & StoryParams>;
31
+
32
+ type Story = StoryObj<ZenTextareaComponent & StoryParams>;
33
+
34
+ export const Default: Story = {
35
+ render: args => ({
36
+ template: `
37
+ <textarea
38
+ zen-textarea
39
+ placeholder="${args.placeholder}"
40
+ ${args.required ? 'required' : ''}
41
+ ${args.autoresize ? 'autoresize' : ''}
42
+ ${args.disabled ? 'disabled' : ''}
43
+ >${args.value}</textarea>`,
44
+ }),
45
+ };
46
+
47
+ export const WithLabel: Story = {
48
+ render: () => ({
49
+ template: `
50
+ <div style="display: flex; flex-direction: column">
51
+ <label for="label-example"> With label </label>
52
+ <textarea zen-textarea id="label-example"></textarea>
53
+ </div>
54
+ `,
55
+ }),
56
+ };
57
+
58
+ export const Autoresize: Story = {
59
+ render: args => ({
60
+ props: { ...args },
61
+ template: `
62
+ <textarea zen-textarea autoresize style="max-width: 300px">Start typing...</textarea>
63
+ `,
64
+ }),
65
+ };
@@ -10,7 +10,7 @@
10
10
  "type": "array",
11
11
  "items": {
12
12
  "type": "string",
13
- "enum": ["avatar", "button", "input"]
13
+ "enum": ["avatar", "button", "checkbox", "input", "textarea"]
14
14
  },
15
15
  "multiselect": true,
16
16
  "x-prompt": "Which component should be generated?"