Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions api-generator/api-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,30 @@ async function main() {
};

component_props_group.children.forEach((prop) => {
const rawType =
prop.getSignature && prop.getSignature.type
? prop.getSignature.type.toString()
: prop.type
? prop.type.toString()
: null;
const isSignalInput = rawType?.startsWith('InputSignal<');
props.values.push({
name: prop.name,
optional: prop.flags.isOptional,
readonly: prop.flags.isReadonly,
type:
prop.getSignature && prop.getSignature.type
? prop.getSignature.type.toString()
: prop.type
? prop.type.toString()
: null,
type: unwrapSignalType(rawType),
default:
(prop.type &&
prop.type.name === 'boolean' &&
!prop.defaultValue
? 'false'
: prop.defaultValue
: prop.defaultValue &&
!(isSignalInput && prop.defaultValue === '...')
? prop.defaultValue.replace(/^'|'$/g, '')
: undefined) ??
getDefaultValue(prop.setSignature) ??
getDefaultValue(prop.getSignature),
getDefaultValue(prop.getSignature) ??
getDefaultValue(prop),
description: (
prop.getSignature?.comment?.summary ||
prop.setSignature?.comment?.summary ||
Expand Down Expand Up @@ -622,6 +626,12 @@ function extractParameter(emitter) {
}
}

const unwrapSignalType = (type) => {
if (!type) return type;
const match = type.match(/^InputSignal<(.+)>$/);
return match ? match[1] : type;
};

const isProcessable = (value) => {
return value && value.children && value.children.length;
};
Expand Down
2 changes: 1 addition & 1 deletion playwright/cps-accessibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const components: ComponentEntry[] = [
// name: 'Expansion panel',
// selector: 'cps-expansion-panel'
// },
// { route: '/file-upload', name: 'File upload', selector: 'cps-file-upload' },
{ route: '/file-upload', name: 'File upload', selector: 'cps-file-upload' },
// { route: '/icon', name: 'Icon', selector: 'cps-icon' },
// { route: '/info-circle', name: 'Info circle', selector: 'cps-info-circle' },
// { route: '/input', name: 'Input', selector: 'cps-input' },
Expand Down
16 changes: 8 additions & 8 deletions projects/composition/src/app/api-data/cps-divider.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
"name": "vertical",
"optional": false,
"readonly": false,
"type": "InputSignal<boolean>",
"default": "...",
"type": "boolean",
"default": "false",
"description": "Determines whether the divider is vertically aligned."
},
{
"name": "color",
"optional": false,
"readonly": false,
"type": "InputSignal<string>",
"default": "...",
"type": "string",
"default": "line-mid",
"description": "Color of the divider."
},
{
"name": "type",
"optional": false,
"readonly": false,
"type": "InputSignal<CpsDividerType>",
"default": "...",
"type": "CpsDividerType",
"default": "solid",
"description": "Type of the divider."
},
{
"name": "thickness",
"optional": false,
"readonly": false,
"type": "InputSignal<string | number>",
"default": "...",
"type": "string | number",
"default": "1px",
"description": "Thickness of the divider, a number denoting pixels or a string."
}
]
Expand Down
54 changes: 50 additions & 4 deletions projects/composition/src/app/api-data/cps-file-upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"description": "Expected file description. E.g. 'Word document'."
},
{
"name": "width",
"name": "ariaLabel",
"optional": false,
"readonly": false,
"type": "string | number",
"default": "100%",
"description": "Width of the component, a number denoting pixels or a string."
"type": "string",
"default": "Upload file",
"description": "Aria label for the component, used for accessibility."
},
{
"name": "fileInfo",
Expand All @@ -37,6 +37,14 @@
"default": "",
"description": "Expected file info block, explaining some extra stuff about file."
},
{
"name": "disabled",
"optional": false,
"readonly": false,
"type": "boolean",
"default": "false",
"description": "Whether the component is disabled."
},
{
"name": "fileProcessingCallback",
"optional": true,
Expand All @@ -60,6 +68,14 @@
"type": "number",
"default": "12",
"description": "File name tooltip offset for styling."
},
{
"name": "width",
"optional": false,
"readonly": false,
"type": "string | number",
"default": "100%",
"description": "Width of the component, a number denoting pixels or a string."
}
]
},
Expand All @@ -86,6 +102,36 @@
],
"description": "Callback to invoke when file upload fails."
},
{
"name": "fileProcessed",
"parameters": [
{
"name": "value",
"type": "File"
}
],
"description": "Callback to invoke when file is processed."
},
{
"name": "fileProcessingFailed",
"parameters": [
{
"name": "value",
"type": "string"
}
],
"description": "Callback to invoke when file processing fails."
},
{
"name": "fileProcessingCancelled",
"parameters": [
{
"name": "value",
"type": "string"
}
],
"description": "Callback to invoke when file processing is cancelled."
},
{
"name": "uploadedFileRemoved",
"parameters": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:host {
.section-title {
color: var(--cps-color-calm);
color: var(--cps-color-depth);
margin-top: 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2 class="section-title">
File upload component with the dependency on selected file extension
</h2>
<div>
<div class="section-body">
<p>
<cps-button-toggle
label="File extension"
Expand All @@ -13,34 +13,64 @@ <h2 class="section-title">
</cps-button-toggle>
<br />
<cps-file-upload
#fileUpload
[extensions]="[selectedFileUploadType.value]"
[fileDesc]="selectedFileUploadType!.label || ''"
width="400"
width="25rem"
fileNameTooltipPosition="bottom"
[fileProcessingCallback]="processUploadedFile"
(fileUploadFailed)="onFileUploadFailed($event)"
(fileUploaded)="onFileUploaded($event)"
(uploadedFileRemoved)="onUploadedFileRemoved($event)">
</cps-file-upload>
</p>
<cps-divider />
</div>

<cps-divider />

<h2 class="section-title">File upload component with extra info</h2>
<div>
<div class="section-body">
<p>
<cps-file-upload
[extensions]="['.jpg', '.png', 'pdf']"
[fileInfo]="fileInfo"
fileDesc="Pictures or PDFs"
ariaLabel="Upload pictures or PDFs"
width="31.25rem"
fileNameTooltipOffset="15"
[fileProcessingCallback]="processUploadedFile"
(fileProcessingFailed)="onFileProcessingFailed($event)"
(fileProcessingCancelled)="onFileProcessingCancelled($event)"
(fileUploadFailed)="onFileUploadFailed($event)"
(fileUploaded)="onFileUploaded($event)"
(fileProcessed)="onFileProcessed($event)"
(uploadedFileRemoved)="onUploadedFileRemoved($event)">
</cps-file-upload>
</p>
<cps-divider />
</div>

<h2 class="section-title">Disabled file upload component</h2>
<div class="section-body">
<p>
<cps-file-upload
[extensions]="['.jpg', '.png', 'pdf']"
[fileInfo]="fileInfo"
fileDesc="Pictures or PDFs"
width="500"
width="31.25rem"
fileNameTooltipOffset="15"
[disabled]="isDisabled"
[fileProcessingCallback]="processUploadedFile"
(fileProcessingFailed)="onFileProcessingFailed($event)"
(fileProcessingCancelled)="onFileProcessingCancelled($event)"
(fileUploadFailed)="onFileUploadFailed($event)"
(fileUploaded)="onFileUploaded($event)"
(fileProcessed)="onFileProcessed($event)"
(uploadedFileRemoved)="onUploadedFileRemoved($event)">
</cps-file-upload>
</p>
<cps-button
label="Toggle disabled"
(clicked)="toggleDisabled()"
size="small">
</cps-button>
</div>
</app-component-docs-viewer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
:host {
.section-title {
color: var(--cps-color-depth);
}
.section-title:first-child {
margin-top: 0;
}
.section-title,
.section-body {
margin-left: 0.5rem;
}
.section-body:last-child {
margin-bottom: 0.5rem;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component } from '@angular/core';
import { Component, ViewChild } from '@angular/core';
import {
CpsFileUploadComponent,
CpsButtonToggleComponent,
CpsButtonToggleOption,
CpsDividerComponent
CpsDividerComponent,
CpsButtonComponent
} from 'cps-ui-kit';
import { Observable, catchError, from, map, of } from 'rxjs';
import { Observable, catchError, delay, from, map, of } from 'rxjs';

import ComponentData from '../../api-data/cps-file-upload.json';
import { ComponentDocsViewerComponent } from '../../components/component-docs-viewer/component-docs-viewer.component';
Expand All @@ -14,6 +15,7 @@
selector: 'app-file-upload-page',
imports: [
CpsButtonToggleComponent,
CpsButtonComponent,
CpsFileUploadComponent,
ComponentDocsViewerComponent,
CpsDividerComponent
Expand All @@ -22,31 +24,36 @@
styleUrls: ['./file-upload-page.component.scss'],
host: { class: 'composition-page' }
})
export class FileUploadPageComponent {
@ViewChild('fileUpload') fileUpload?: CpsFileUploadComponent;

componentData = ComponentData;

fileUploadOptions: CpsButtonToggleOption[] = [
{ label: 'JPG image', value: '.jpg' },
{ label: 'PDF document', value: '.pdf' },
{ label: 'PNG image', value: '.png' }
];

selectedFileUploadType: CpsButtonToggleOption = this.fileUploadOptions[0];

isDisabled = true;

fileInfo: string =
'The file should be a small sample file to infer the schema, which will be shown in the next step';

processUploadedFile(file: File): Observable<boolean> {
return from(file.text()).pipe(
delay(3000),
map((fileContentsAsText) => {
console.log(fileContentsAsText);
return true;
}),
catchError((error) => {
console.error('Error reading file', error);
return of(false);
})
);

Check warning on line 56 in projects/composition/src/app/pages/file-upload-page/file-upload-page.component.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

onFileUploaded(file: File) {
Expand All @@ -57,16 +64,33 @@
console.log('File upload failed', fileName);
}

onFileProcessed(file: File) {
console.log('File processed', file?.name);
}

onFileProcessingFailed(fileName: string) {
console.log('File processing failed', fileName);
}

onFileProcessingCancelled(fileName: string) {

Check warning on line 75 in projects/composition/src/app/pages/file-upload-page/file-upload-page.component.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
console.log('File processing cancelled', fileName);

Check warning on line 76 in projects/composition/src/app/pages/file-upload-page/file-upload-page.component.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

onUploadedFileRemoved(fileName: string) {
console.log('File removed: ', fileName);
}

onFileExtensionChanged(event: string) {
this.fileUpload?.resetState();
const foundSelectedItem = this.fileUploadOptions.find(
(item) => item.value === event
);
if (foundSelectedItem) {
this.selectedFileUploadType = foundSelectedItem;
}
}

toggleDisabled() {
this.isDisabled = !this.isDisabled;
}
}

Check warning on line 96 in projects/composition/src/app/pages/file-upload-page/file-upload-page.component.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
Loading
Loading