@ng-zen/cli 19.0.0-alpha.2 → 19.0.0-alpha.3
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 +0 -6
- package/package.json +1 -1
- package/schematics/components/components-generator.js.map +1 -1
- package/schematics/components/components-generator.ts +1 -1
- package/schematics/components/files/input/index.ts +1 -0
- package/schematics/components/files/input/input.component.scss +28 -0
- package/schematics/components/files/input/input.component.spec.ts +22 -0
- package/schematics/components/files/input/input.component.ts +85 -0
- package/schematics/components/files/input/input.stories.ts +46 -0
- package/schematics/components/schema.json +1 -1
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 +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' | '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' | 'input';
|
|
4
4
|
|
|
5
5
|
export interface ComponentGeneratorSchema extends GeneratorSchemaBase {
|
|
6
6
|
components: ComponentType[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './input.component';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
$border: var(--zen-input-border, 1px solid #cbcbcb);
|
|
2
|
+
$border-radius: var(--zen-input-border-radius, 8px);
|
|
3
|
+
$padding: var(--zen-input-padding, 0.5rem 1rem);
|
|
4
|
+
$outline: var(--zen-outline, 1px solid #999);
|
|
5
|
+
$border-invalid: var(--zen-error, #dc2626);
|
|
6
|
+
|
|
7
|
+
input {
|
|
8
|
+
border: $border;
|
|
9
|
+
border-radius: $border-radius;
|
|
10
|
+
padding: $padding;
|
|
11
|
+
|
|
12
|
+
&:disabled {
|
|
13
|
+
opacity: 0.6;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&:focus-visible {
|
|
17
|
+
outline: $outline;
|
|
18
|
+
box-shadow: 0 1px 4px #9999993f inset;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&:user-invalid {
|
|
22
|
+
border-color: $border-invalid;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&::placeholder {
|
|
26
|
+
color: #999;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -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,85 @@
|
|
|
1
|
+
import { booleanAttribute, ChangeDetectionStrategy, Component, forwardRef, input, model } from '@angular/core';
|
|
2
|
+
import { ControlValueAccessor, 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/Kordrad/ng-zen?tab=BSD-2-Clause-1-ov-file|BSD-2-Clause}
|
|
16
|
+
* @see [GitHub](https://github.com/Kordrad/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
|
+
[value]="value()"
|
|
28
|
+
(blur)="onTouched()"
|
|
29
|
+
(input)="onInputChange($event)"
|
|
30
|
+
/>
|
|
31
|
+
`,
|
|
32
|
+
styleUrls: ['./input.component.scss'],
|
|
33
|
+
providers: [
|
|
34
|
+
{
|
|
35
|
+
provide: NG_VALUE_ACCESSOR,
|
|
36
|
+
useExisting: forwardRef(() => ZenInputComponent),
|
|
37
|
+
multi: true,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
41
|
+
})
|
|
42
|
+
export class ZenInputComponent implements ControlValueAccessor {
|
|
43
|
+
/** Holds the current input value. */
|
|
44
|
+
readonly value = model('');
|
|
45
|
+
/** Determines if the input is disabled. */
|
|
46
|
+
readonly disabled = model(false);
|
|
47
|
+
/** Determines if the input is required.*/
|
|
48
|
+
readonly required = input(false, { transform: booleanAttribute });
|
|
49
|
+
/** Sets the HTML id attribute for the input element.*/
|
|
50
|
+
readonly id = input<string>();
|
|
51
|
+
/** Provides a hint or example text that will be displayed */
|
|
52
|
+
readonly placeholder = input<string>();
|
|
53
|
+
|
|
54
|
+
/** @ignore */
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
56
|
+
onChange: (value: string) => void = () => {};
|
|
57
|
+
/** @ignore */
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
59
|
+
onTouched: () => void = () => {};
|
|
60
|
+
|
|
61
|
+
/** @ignore */
|
|
62
|
+
writeValue(value: string): void {
|
|
63
|
+
this.value.set(value);
|
|
64
|
+
}
|
|
65
|
+
/** @ignore */
|
|
66
|
+
registerOnChange(fn: (value: string) => void): void {
|
|
67
|
+
this.onChange = fn;
|
|
68
|
+
}
|
|
69
|
+
/** @ignore */
|
|
70
|
+
registerOnTouched(fn: () => void): void {
|
|
71
|
+
this.onTouched = fn;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @ignore */
|
|
75
|
+
setDisabledState(isDisabled: boolean): void {
|
|
76
|
+
this.disabled.set(isDisabled);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @ignore */
|
|
80
|
+
onInputChange(event: Event): void {
|
|
81
|
+
const newValue = (event.target as HTMLInputElement).value;
|
|
82
|
+
this.value.set(newValue);
|
|
83
|
+
this.onChange(newValue);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
},
|
|
14
|
+
args: {
|
|
15
|
+
value: '',
|
|
16
|
+
placeholder: '',
|
|
17
|
+
disabled: false,
|
|
18
|
+
required: false,
|
|
19
|
+
},
|
|
20
|
+
} satisfies Meta<ZenInputComponent>;
|
|
21
|
+
|
|
22
|
+
type Story = StoryObj<ZenInputComponent>;
|
|
23
|
+
|
|
24
|
+
export const Default: Story = {
|
|
25
|
+
render: args => ({
|
|
26
|
+
props: { ...args },
|
|
27
|
+
template: `
|
|
28
|
+
<zen-input
|
|
29
|
+
[disabled]="${args.disabled}"
|
|
30
|
+
[value]="'${args.value}'"
|
|
31
|
+
[placeholder]="${args.placeholder}"
|
|
32
|
+
${args.required ? 'required' : ''}
|
|
33
|
+
/>`,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const WithLabel: Story = {
|
|
38
|
+
render: () => ({
|
|
39
|
+
template: `
|
|
40
|
+
<div style="display: flex; flex-direction: column">
|
|
41
|
+
<label for="label-example"> With label </label>
|
|
42
|
+
<zen-input id="label-example"/>
|
|
43
|
+
</div>
|
|
44
|
+
`,
|
|
45
|
+
}),
|
|
46
|
+
};
|