Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(dynamic-forms): introduction to dynamic-forms module. closes(#8) #204

Merged
merged 46 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8981d0a
upstream dynamic forms without dates
Dec 9, 2016
a8f5f7e
added docs scaffolding for dynamic forms
Dec 9, 2016
fef69a3
added path mapping for `@covalent`
Dec 9, 2016
05ae454
remove stepAttrs from dynamic form docs
Dec 9, 2016
882dfb8
added type and element to test things
Dec 9, 2016
047fe7e
Merge branch 'develop' into feature/dynamic-forms
Dec 12, 2016
ccf75d9
Merge branch 'develop' into feature/dynamic-forms
Dec 20, 2016
7857f04
added TD_DYNAMIC_FORMS constant
Dec 20, 2016
678689b
renamed enums and interfaces
Dec 20, 2016
3aa7ed6
added checkbox dynamic element
Dec 20, 2016
232e7a5
added dynamic slider element
Dec 20, 2016
a5d8ca3
test input element type
Dec 20, 2016
4900806
validate element name against special characters
Dec 20, 2016
7a8ff16
duplicated name validation
Dec 20, 2016
fa68638
added materially label to dynamic slider
Dec 20, 2016
6e90391
added package.json
Dec 20, 2016
c11d852
added blank README.md
Dec 20, 2016
3458478
changed imports to specific validators
Dec 20, 2016
893d76f
merge with develop
Dec 20, 2016
c984342
use relative path for core.module (gulp-typescript complains)
Dec 20, 2016
0ff5901
replace relative core.module path with @covalent/core on build
Dec 20, 2016
0335558
added demos per group family of elements
Dec 20, 2016
4dab470
set name as id in dynamic element
Dec 20, 2016
4228260
added doc blocks for dynamic-forms
Dec 20, 2016
468d92e
updated properties docs in dynamic-forms
Dec 20, 2016
5db1619
added docs for dynamic-forms
Dec 21, 2016
45b3695
dynamic-forms.service unit test
Dec 21, 2016
627dca4
added more exports to dynamic-forms
Dec 21, 2016
94a8f74
added unit tests for dynamic-forms.component
Dec 21, 2016
950afdd
fix tslint errors
Dec 21, 2016
d2e0b83
added README.md
Dec 21, 2016
3518d66
fixed unit tests
Dec 21, 2016
87cbbe9
Merge branch 'develop' into feature/dynamic-forms
kyleledbetter Dec 26, 2016
436d125
Merge branch 'develop' into feature/dynamic-forms
kyleledbetter Dec 26, 2016
48152df
merge develop
Dec 28, 2016
e3d063e
added relative path to dynamic-forms components
Dec 28, 2016
83bdca0
favor md-input-container in dynamic-input
Dec 28, 2016
ea2e517
remove value and added thumbLabel on slider
Dec 28, 2016
b43de84
added textarea dynamic component and updated docs
Dec 28, 2016
4e3d2f4
unit tests for dynamic-textarea
Dec 28, 2016
e866c3c
added dynamic select component + docs and demo
Dec 29, 2016
8ebcb66
updated unit tests with select
Dec 29, 2016
96c8280
updated README.md
Dec 29, 2016
752b822
Merge branch 'develop' into feature/dynamic-forms
kyleledbetter Dec 29, 2016
6f104fd
update(dynamic-forms): Number support coming soon
Dec 29, 2016
92fdebd
Merge branch 'develop' into feature/dynamic-forms
kyleledbetter Dec 29, 2016
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
4 changes: 4 additions & 0 deletions scripts/inline-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function inlineResources(globs) {
.then(content => inlineTemplate(filePath, content))
.then(content => inlineStyle(filePath, content))
.then(content => removeModuleId(filePath, content))
.then(content => replaceRelativePath(filePath, content))
.then(content => writeFile(filePath, content))
.catch(err => {
console.error('An error occured: ', err);
Expand Down Expand Up @@ -102,6 +103,9 @@ function inlineStyle(filePath, content) {
});
}

function replaceRelativePath(_, content) {
return content.replace(/((\.\.\/)+core)/gm, '@covalent/core');
}

/**
* Remove every mention of `moduleId: module.id`.
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CovalentHighlightModule } from '../platform/highlight';
import { CovalentHttpModule } from '../platform/http';
import { CovalentMarkdownModule } from '../platform/markdown';
import { CovalentChartsModule } from '../platform/charts';
import { CovalentDynamicFormsModule } from '../platform/dynamic-forms';

@NgModule({
declarations: [
Expand All @@ -31,6 +32,7 @@ import { CovalentChartsModule } from '../platform/charts';
CovalentHighlightModule.forRoot(),
CovalentMarkdownModule.forRoot(),
CovalentChartsModule.forRoot(),
CovalentDynamicFormsModule.forRoot(),
appRoutes,
], // modules needed to run this module
providers: [
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/components/components.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export class ComponentsComponent {
icon: 'search',
route: 'search',
title: 'Search',
}, {
description: 'Build forms from a JS object',
icon: 'format_align_center',
route: 'dynamic-forms',
title: 'Dynamic Forms',
}, {
description: 'Responsive service & directive',
icon: 'devices',
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/components/components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import { ChartsDemoComponent } from './charts/charts.component';
import { DataTableDemoComponent } from './data-table/data-table.component';
import { PagingDemoComponent } from './paging/paging.component';
import { SearchDemoComponent } from './search/search.component';
import { DynamicFormsDemoComponent } from './dynamic-forms/dynamic-forms.component';
import { MaterialComponentsComponent, DialogComponent } from './material-components/material-components.component';

import { CovalentCoreModule } from '../../../platform/core';
import { CovalentHighlightModule } from '../../../platform/highlight';
import { CovalentMarkdownModule } from '../../../platform/markdown';
import { CovalentChartsModule } from '../../../platform/charts';
import { CovalentDynamicFormsModule } from '../../../platform/dynamic-forms';

@NgModule({
declarations: [
Expand All @@ -49,6 +51,7 @@ import { CovalentChartsModule } from '../../../platform/charts';
DataTableDemoComponent,
PagingDemoComponent,
SearchDemoComponent,
DynamicFormsDemoComponent,
MaterialComponentsComponent,
DialogComponent,
],
Expand All @@ -57,6 +60,7 @@ import { CovalentChartsModule } from '../../../platform/charts';
CovalentHighlightModule.forRoot(),
CovalentMarkdownModule.forRoot(),
CovalentChartsModule.forRoot(),
CovalentDynamicFormsModule.forRoot(),
componentsRoutes,
],
entryComponents: [ DialogComponent ],
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/components/components.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ChartsDemoComponent } from './charts/charts.component';
import { DataTableDemoComponent } from './data-table/data-table.component';
import { PagingDemoComponent } from './paging/paging.component';
import { SearchDemoComponent } from './search/search.component';
import { DynamicFormsDemoComponent } from './dynamic-forms/dynamic-forms.component';
import { MaterialComponentsComponent } from './material-components/material-components.component';

const routes: Routes = [{
Expand Down Expand Up @@ -79,6 +80,9 @@ const routes: Routes = [{
}, {
component: PagingDemoComponent,
path: 'paging',
}, {
component: DynamicFormsDemoComponent,
path: 'dynamic-forms',
},
],
component: ComponentsComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<md-card>
<md-card-title>Dynamic Forms</md-card-title>
<md-card-subtitle>Build forms from a JS object</md-card-subtitle>
<md-divider></md-divider>
<md-card-content>
<h3 class="md-title">Dynamic Text Elements</h3>
<md-divider></md-divider>
<md-tab-group md-stretch-tabs>
<md-tab>
<template md-tab-label>Demo</template>
<td-dynamic-forms [elements]="textElements">
</td-dynamic-forms>
</md-tab>
<md-tab>
<template md-tab-label>Code</template>
<p>HTML:</p>
<td-highlight lang="html">
<![CDATA[
<td-dynamic-forms [elements]="textElements">
</td-dynamic-forms>
]]>
</td-highlight>
<p>Typescript:</p>
<td-highlight lang="typescript">
{{textElements | json}}
</td-highlight>
</md-tab>
</md-tab-group>
</md-card-content>
</md-card>
<md-card>
<md-card-content>
<h3 class="md-title">Dynamic Number Elements</h3>
<md-divider></md-divider>
<md-tab-group md-stretch-tabs>
<md-tab>
<template md-tab-label>Demo</template>
<td-dynamic-forms [elements]="numberElements">
</td-dynamic-forms>
</md-tab>
<md-tab>
<template md-tab-label>Code</template>
<p>HTML:</p>
<td-highlight lang="html">
<![CDATA[
<td-dynamic-forms [elements]="numberElements">
</td-dynamic-forms>
]]>
</td-highlight>
<p>Typescript:</p>
<td-highlight lang="typescript">
{{numberElements | json}}
</td-highlight>
</md-tab>
</md-tab-group>
</md-card-content>
</md-card>
<md-card>
<md-card-content>
<h3 class="md-title">Dynamic Boolean Elements</h3>
<md-divider></md-divider>
<md-tab-group md-stretch-tabs>
<md-tab>
<template md-tab-label>Demo</template>
<td-dynamic-forms [elements]="booleanElements">
</td-dynamic-forms>
</md-tab>
<md-tab>
<template md-tab-label>Code</template>
<p>HTML:</p>
<td-highlight lang="html">
<![CDATA[
<td-dynamic-forms [elements]="booleanElements">
</td-dynamic-forms>
]]>
</td-highlight>
<p>Typescript:</p>
<td-highlight lang="typescript">
{{booleanElements | json}}
</td-highlight>
</md-tab>
</md-tab-group>
</md-card-content>
</md-card>
<md-card>
<md-card-content>
<h3 class="md-title">Dynamic Array Elements</h3>
<md-divider></md-divider>
<md-tab-group md-stretch-tabs>
<md-tab>
<template md-tab-label>Demo</template>
<td-dynamic-forms [elements]="arrayElements">
</td-dynamic-forms>
</md-tab>
<md-tab>
<template md-tab-label>Code</template>
<p>HTML:</p>
<td-highlight lang="html">
<![CDATA[
<td-dynamic-forms [elements]="arrayElements">
</td-dynamic-forms>
]]>
</td-highlight>
<p>Typescript:</p>
<td-highlight lang="typescript">
{{arrayElements | json}}
</td-highlight>
</md-tab>
</md-tab-group>
</md-card-content>
</md-card>
<md-card>
<md-card-title>TdDynamicFormsComponent</md-card-title>
<md-card-subtitle>How to use this component</md-card-subtitle>
<md-divider></md-divider>
<md-card-content>
<h2><code><![CDATA[<td-dynamic-forms>]]></code></h2>
<p>Use <code><![CDATA[<td-dynamic-forms>]]></code> element to generate a form dynamically.</p>
<p>Pass an array of javascript objects that implement [ITdDynamicElementConfig] with the information to be rendered to the [elements] attribute.</p>
<td-highlight lang="typescript">
<![CDATA[
export interface ITdDynamicElementConfig {
label?: string;
name: string;
type: TdDynamicType | TdDynamicElement;
required?: boolean;
min?: any;
max?: any;
default?: any;
}
]]>
</td-highlight>
<h3>Properties:</h3>
<p>The <code><![CDATA[<td-dynamic-forms>]]></code> component has {{dynamicFormsAttrs.length}} properties:</p>
<md-list>
<template let-attr let-last="attr" ngFor [ngForOf]="dynamicFormsAttrs">
<a md-list-item layout-align="row">
<h3 md-line> {{attr.name}}: <span>{{attr.type}}</span></h3>
<p md-line> {{attr.description}} </p>
</a>
<md-divider *ngIf="!last"></md-divider>
</template>
</md-list>
<h3>Example:</h3>
<p>HTML:</p>
<td-highlight lang="html">
<![CDATA[
<td-dynamic-forms [elements]="elements">
</td-dynamic-forms>
]]>
</td-highlight>
<p>Typescript:</p>
<td-highlight lang="typescript">
<![CDATA[
import { ITdDynamicElementConfig, TdDynamicElement, TdDynamicType } from '@covalent/dynamic-forms';
...
})
export class Demo {
elements: ITdDynamicElementConfig[] = [{
name: 'input-without-label',
type: TdDynamicElement.Input,
required: false,
}, {
name: 'input-with-label',
label: 'Input Label',
type: TdDynamicElement.Input,
required: true,
}, {
name: 'text-with-default',
type: TdDynamicType.Text,
required: false,
default: 'Default',
}];
}
]]>
</td-highlight>
<h3>Setup:</h3>
<p>Import the [CovalentDynamicFormsModule] using the <code>forRoot()</code> method in your NgModule:</p>
<td-highlight lang="typescript">
<![CDATA[
import { CovalentDynamicFormsModule } from '@covalent/dynamic-forms';
@NgModule({
imports: [
CovalentDynamicFormsModule.forRoot(),
...
],
...
})
export class MyModule {}
]]>
</td-highlight>
</md-card-content>
</md-card>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Component } from '@angular/core';
import { TdDynamicType, ITdDynamicElementConfig, TdDynamicElement } from '@covalent/dynamic-forms';

@Component({
selector: 'dynamic-forms-demo',
styleUrls: [ './dynamic-forms.component.scss' ],
templateUrl: './dynamic-forms.component.html',
})
export class DynamicFormsDemoComponent {

dynamicFormsAttrs: any[] = [{
description: `JS Object that will render the elements depending on its config.
[name] property is required.`,
name: 'elements',
type: 'ITdDynamicElementConfig[]',
}, {
description: `Getter property for dynamic [FormGroup].`,
name: 'form',
type: 'get(): FormGroup',
}, {
description: `Getter property for [valid] of dynamic [FormGroup].`,
name: 'valid',
type: 'get(): boolean',
}, {
description: `Getter property for [value] of dynamic [FormGroup].`,
name: 'value',
type: 'get(): any',
}, {
description: `Getter property for [errors] of dynamic [FormGroup].`,
name: 'errors',
type: 'get(): {[name: string]: any}',
}, {
description: `Getter property for [controls] of dynamic [FormGroup].`,
name: 'controls',
type: 'get(): {[key: string]: AbstractControl}',
}];

textElements: ITdDynamicElementConfig[] = [{
name: 'input',
type: TdDynamicElement.Input,
required: false,
}, {
name: 'required-input',
label: 'Input Label',
type: TdDynamicElement.Input,
required: true,
}, {
name: 'textarea',
type: TdDynamicElement.Textarea,
required: false,
}, {
name: 'text',
type: TdDynamicType.Text,
required: false,
default: 'Default',
}];

numberElements: ITdDynamicElementConfig[] = [{
name: 'number',
label: 'Number (coming soon)',
type: TdDynamicType.Number,
required: true,
min: 18,
max: 70,
}, {
name: 'slider',
type: TdDynamicElement.Slider,
min: 18,
max: 70,
}];

booleanElements: ITdDynamicElementConfig[] = [{
name: 'boolean',
label: 'Boolean Label',
type: TdDynamicType.Boolean,
default: false,
}, {
name: 'slide-toggle',
type: TdDynamicElement.SlideToggle,
default: true,
}, {
name: 'checkbox',
type: TdDynamicElement.Checkbox,
}];

arrayElements: ITdDynamicElementConfig[] = [{
name: 'array',
type: TdDynamicType.Array,
selections: ['Test1', 'Test2', 'Test3', 'Test4'],
default: 'Test1',
}, {
name: 'required-select',
type: TdDynamicElement.Select,
selections: ['Test1', 'Test2', 'Test3', 'Test4'],
required: true,
}];
}
5 changes: 5 additions & 0 deletions src/app/components/components/overview/overview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export class ComponentsOverviewComponent {
icon: 'search',
route: 'search',
title: 'Search',
}, {
color: 'green-700',
icon: 'format_align_center',
route: 'dynamic-forms',
title: 'Dynamic Forms',
}, {
color: 'red-700',
icon: 'devices',
Expand Down
Loading