feat(export): Added export deltagare. (TV-872)
Squashed commit of the following: commit 9c06b7f1d44a4b48d7f31a22b6bfbd233e09d2f7 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 15:07:15 2021 +0100 Updated api endpoint commit f9bfbecda6d03b70d87febbada920d0eca798b1f Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 15:01:13 2021 +0100 Updated libs commit 9edb413d537288fa0708b8a04eb54f801ebc23a0 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 14:58:13 2021 +0100 Added @types/file-saver commit 624affac55ce771fd58e2770a0d4a98233a8e9ba Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 14:42:29 2021 +0100 Updated libs commit 65dae1d906bbcec474581692b2aced9e47d2484c Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 14:36:42 2021 +0100 Added utils lib config commit 223bd59724663523bdbaf87b5502396156ddb9eb Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 14:06:13 2021 +0100 Added validation commit 166dfcf0448155ac21c0eaa904b4ce1271f73193 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 13:25:35 2021 +0100 Changed styling and removed some fake data commit 3906f2793dd52b626b95c13e115495451332c894 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 13:18:52 2021 +0100 Added digi-ng datepicker commit de0d51434d15cac5476303d4b417c591da16fd8f Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Tue Nov 2 12:31:48 2021 +0100 Added checkbox
This commit is contained in:
18
libs/ui/src/checkbox/checkbox.component.html
Normal file
18
libs/ui/src/checkbox/checkbox.component.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<div class="ui-checkbox" [ngClass]="{'ui-checkbox--invalid': uiInvalid && uiValidationMessage}">
|
||||
<digi-form-checkbox
|
||||
[afId]="uiId"
|
||||
[afIndeterminate]="uiIndeterminate"
|
||||
[afName]="uiName"
|
||||
[afRequired]="uiRequired"
|
||||
[afValidation]="uiInvalid ? 'error' : 'neutral'"
|
||||
[afVariation]="uiSecondary ? 'secondary' : 'primary'"
|
||||
[afLabel]="labelText"
|
||||
[afChecked]="currentValue"
|
||||
(afOnChange)="checkForChange($event.detail.target.checked)"
|
||||
></digi-form-checkbox>
|
||||
<div aria-atomic="true" role="alert">
|
||||
<digi-form-validation-message *ngIf="uiInvalid && uiValidationMessage" af-variation="error"
|
||||
>{{uiValidationMessage}}</digi-form-validation-message
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
8
libs/ui/src/checkbox/checkbox.component.scss
Normal file
8
libs/ui/src/checkbox/checkbox.component.scss
Normal file
@@ -0,0 +1,8 @@
|
||||
.ui-checkbox {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
&--invalid {
|
||||
gap: var(--digi--layout--gutter--xs);
|
||||
}
|
||||
}
|
||||
23
libs/ui/src/checkbox/checkbox.component.spec.ts
Normal file
23
libs/ui/src/checkbox/checkbox.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
import { FormCheckboxComponent } from './form-checkbox.component';
|
||||
|
||||
export class MockInjector {
|
||||
get = jest.fn();
|
||||
}
|
||||
|
||||
// tslint:disable-next-line: max-classes-per-file
|
||||
export class MockChangeDetectorRef {
|
||||
markForCheck = jest.fn();
|
||||
detach = jest.fn();
|
||||
detectChanges = jest.fn();
|
||||
reattach = jest.fn();
|
||||
checkNoChanges = jest.fn();
|
||||
}
|
||||
|
||||
describe('FormCheckboxComponent', () => {
|
||||
let component: FormCheckboxComponent;
|
||||
it('should create', () => {
|
||||
component = new FormCheckboxComponent(new MockInjector(), new MockChangeDetectorRef());
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
16
libs/ui/src/checkbox/checkbox.component.stories.ts
Normal file
16
libs/ui/src/checkbox/checkbox.component.stories.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { CheckboxComponent } from './checkbox.component';
|
||||
import { UiCheckboxModule } from './checkbox.module';
|
||||
|
||||
export default { title: 'Checkbox', component: CheckboxComponent };
|
||||
|
||||
const componentModule = {
|
||||
moduleMetadata: {
|
||||
imports: [ReactiveFormsModule, UiCheckboxModule],
|
||||
},
|
||||
};
|
||||
|
||||
export const standard = () => ({
|
||||
...componentModule,
|
||||
template: '<ui-checkbox></ui-checkbox>',
|
||||
});
|
||||
111
libs/ui/src/checkbox/checkbox.component.ts
Normal file
111
libs/ui/src/checkbox/checkbox.component.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import {
|
||||
AfterViewInit,
|
||||
ChangeDetectionStrategy,
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
EventEmitter,
|
||||
Injector,
|
||||
Input,
|
||||
OnChanges,
|
||||
Output,
|
||||
SimpleChanges,
|
||||
} from '@angular/core';
|
||||
import { ControlValueAccessor, NgControl, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { uuid } from '@utils/uuid.util';
|
||||
|
||||
/**
|
||||
* A checkbox input. Implemented with control value accessor
|
||||
*
|
||||
* ## Usage
|
||||
* ``import {UiCheckboxModule} from '@ui/checkbox/checkbox.module';``
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ui-checkbox',
|
||||
templateUrl: './checkbox.component.html',
|
||||
styleUrls: ['./checkbox.component.scss'],
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
useExisting: CheckboxComponent,
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class CheckboxComponent implements AfterViewInit, ControlValueAccessor, OnChanges {
|
||||
@Input() uiInvalid: boolean;
|
||||
@Input() uiValidationMessage: string;
|
||||
@Input() uiSecondary: boolean;
|
||||
@Input() uiIndeterminate: boolean = false;
|
||||
@Input() uiLabel: string = '';
|
||||
@Input() uiRequired: boolean;
|
||||
@Input() uiId: string = uuid();
|
||||
@Input() uiName: string;
|
||||
@Input() uiAnnounceIfOptional: boolean = false;
|
||||
@Output() uiOnChange: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
name: string | number;
|
||||
|
||||
onTouched: () => {};
|
||||
private onChange: (value: any) => {};
|
||||
private _value: boolean;
|
||||
|
||||
constructor(private injector: Injector, private changeDetectorRef: ChangeDetectorRef) {}
|
||||
|
||||
get currentValue(): boolean {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
get labelText(): string {
|
||||
return `${this.uiLabel}${this._requiredText}`;
|
||||
}
|
||||
|
||||
private get _requiredText() {
|
||||
if (this.uiRequired && !this.uiAnnounceIfOptional) {
|
||||
return ' (obligatoriskt)';
|
||||
}
|
||||
|
||||
if (!this.uiRequired && this.uiAnnounceIfOptional) {
|
||||
return ' (frivilligt)';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
const ngControl: NgControl = this.injector.get(NgControl, null);
|
||||
if (ngControl) {
|
||||
this.name = ngControl.name;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
const ngControl: NgControl = this.injector.get(NgControl, null);
|
||||
if (ngControl) {
|
||||
this.name = ngControl.name;
|
||||
}
|
||||
}
|
||||
|
||||
checkForChange(value: boolean): void {
|
||||
if (this._value !== !!value) {
|
||||
if (this.onChange) {
|
||||
this.onChange(!!value);
|
||||
}
|
||||
this._value = !!value;
|
||||
this.uiOnChange.emit(!!value);
|
||||
}
|
||||
}
|
||||
|
||||
writeValue(value: any): void {
|
||||
this._value = value;
|
||||
this.changeDetectorRef.detectChanges();
|
||||
}
|
||||
|
||||
registerOnChange(fn: (value: string) => {}) {
|
||||
this.onChange = fn;
|
||||
}
|
||||
|
||||
registerOnTouched(fn: () => {}) {
|
||||
this.onTouched = fn;
|
||||
}
|
||||
}
|
||||
11
libs/ui/src/checkbox/checkbox.module.ts
Normal file
11
libs/ui/src/checkbox/checkbox.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
|
||||
import { CheckboxComponent } from './checkbox.component';
|
||||
|
||||
@NgModule({
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||
imports: [CommonModule],
|
||||
declarations: [CheckboxComponent],
|
||||
exports: [CheckboxComponent],
|
||||
})
|
||||
export class UiCheckboxModule {}
|
||||
1
libs/ui/src/test-setup.ts
Normal file
1
libs/ui/src/test-setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
import 'jest-preset-angular';
|
||||
22
libs/utils/.eslintrc.json
Normal file
22
libs/utils/.eslintrc.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"extends": ["../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"extends": ["plugin:@nrwl/nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
|
||||
"parserOptions": { "project": ["libs/utils/tsconfig.*?.json"] },
|
||||
"rules": {
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{ "type": "attribute", "prefix": "mina-sidor-fa-web", "style": "camelCase" }
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{ "type": "element", "prefix": "mina-sidor-fa-web", "style": "kebab-case" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ "files": ["*.html"], "extends": ["plugin:@nrwl/nx/angular-template"], "rules": {} }
|
||||
]
|
||||
}
|
||||
7
libs/utils/README.md
Normal file
7
libs/utils/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# utils
|
||||
|
||||
This library was generated with [Nx](https://nx.dev).
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `nx test utils` to execute the unit tests.
|
||||
23
libs/utils/jest.config.js
Normal file
23
libs/utils/jest.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
displayName: 'utils',
|
||||
preset: '../../jest.preset.js',
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsConfig: '<rootDir>/tsconfig.spec.json',
|
||||
stringifyContentPathRegex: '\\.(html|svg)$',
|
||||
astTransformers: {
|
||||
before: [
|
||||
'jest-preset-angular/build/InlineFilesTransformer',
|
||||
'jest-preset-angular/build/StripStylesTransformer',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
coverageDirectory: '../../coverage/libs/utils',
|
||||
snapshotSerializers: [
|
||||
'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
|
||||
'jest-preset-angular/build/AngularSnapshotSerializer.js',
|
||||
'jest-preset-angular/build/HTMLCommentSerializer.js',
|
||||
],
|
||||
};
|
||||
1
libs/utils/src/test-setup.ts
Normal file
1
libs/utils/src/test-setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
import 'jest-preset-angular';
|
||||
8
libs/utils/src/uuid.util.ts
Normal file
8
libs/utils/src/uuid.util.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// From https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid
|
||||
export function uuid(): string {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
const r = (Math.random() * 16) | 0,
|
||||
v = c == 'x' ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
13
libs/utils/tsconfig.json
Normal file
13
libs/utils/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
19
libs/utils/tsconfig.lib.json
Normal file
19
libs/utils/tsconfig.lib.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"target": "es2015",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"inlineSources": true,
|
||||
"types": [],
|
||||
"lib": ["dom", "es2018"]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"skipTemplateCodegen": true,
|
||||
"strictMetadataEmit": true,
|
||||
"enableResourceInlining": true
|
||||
},
|
||||
"exclude": ["src/test-setup.ts", "**/*.spec.ts"],
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
10
libs/utils/tsconfig.spec.json
Normal file
10
libs/utils/tsconfig.spec.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"files": ["src/test-setup.ts"],
|
||||
"include": ["**/*.spec.ts", "**/*.d.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user