Skip to content

Commit

Permalink
#374 Create divider component (#375)
Browse files Browse the repository at this point in the history
* divider implementation

* enhance readme

* update composition page

* added left border to table expanded row contents according to design guidelines
  • Loading branch information
fateeand authored Apr 24, 2024
1 parent ff3ce62 commit e328bc0
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 17 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

This repository consists of two projects:

- cps-ui-kit - shared components library itself
- composition - application for previewing compositions of components consumed from the library
- `cps-ui-kit` - shared components library itself
- `composition` - application for previewing compositions of components consumed from the library

#### Available components

Expand All @@ -16,6 +16,7 @@ This repository consists of two projects:
- Chip
- Datepicker
- Dialog
- Divider
- Expansion panel
- File upload
- Icon
Expand Down Expand Up @@ -54,20 +55,23 @@ https://www.figma.com/file/JAlfp4zwZIONMWYPbLY4aM/Consumer-products-design-syste

#### Create a new component

- go to projects/cps-ui-kit/src/lib/components directory
- run: ng g c cps-componentname --standalone --prefix
- modify projects/cps-ui-kit/src/public-api.ts to export the component from the library
- update available components list in projects/cps-ui-kit/README.md (keep alphabetical order!)
- go to `projects/cps-ui-kit/src/lib/components` directory
- run: `ng g c cps-componentname --standalone --prefix`
- modify `projects/cps-ui-kit/src/public-api.ts` to export the component from the library
- update available components list in `projects/cps-ui-kit/README.md` (keep alphabetical order!)

Make sure 'ng build cps-ui-kit --watch' is running, so the library will be rebuilt on each change of its contents due to --watch flag
Make sure `ng build cps-ui-kit --watch` is running, so the library will be rebuilt on each change of its contents due to `--watch` flag

#### Create a composition page

- go to projects/composition/src/app/pages directory
- run: ng g c componentname-page --standalone
- there is no need to test composition pages, so manually delete componentname-page.cy.ts file (can't be done automatically with Angular CLI flag, since cypress is used)
- provide host: { class: 'composition-page' } into page @Component
- import the components for the composition page from 'cps-ui-kit', provide them to imports array of @Component
- go to projects/composition/src/app/components/navigation-sidebar.component.ts file and extend \_components array (keep alphabetical order!)
- go to projects/composition/src/app/app-routing.module.ts and add a new route for a new page
- update available components list in README.md (keep alphabetical order!)
- go to `projects/composition/src/app/pages` directory
- run: `ng g c componentname-page --standalone`
- there is no need to test composition pages, so manually delete `componentname-page.component.cy.ts` file (can't be done automatically with Angular CLI flag, since cypress is used)
- provide `host: { class: 'composition-page' }` into page `@Component`
- import the components for the composition page from `cps-ui-kit`, provide them to imports array of `@Component`
- include `ComponentDocsViewerComponent` into `@Component` `imports` array in case of a new component page, include `ServiceDocsViewerComponent` into `@Component` `imports` array in case of a new service page
- import `ComponentData or ServiceData` from '../../api-data/cps-componentname.json' once it is generated
- wrap page html template contents into `<app-component-docs-viewer [componentData]="componentData">...</app-component-docs-viewer>` in case of a new component page, wrap page html template contents into `<app-service-docs-viewer [serviceData]="serviceData">...</app-service-docs-viewer>` in case of a new service page
- go to `projects/composition/src/app/components/navigation-sidebar.component.ts` file and extend `_components` array (keep alphabetical order!)
- go to `projects/composition/src/app/app-routing.module.ts` and add a new route for a new page
- update available components list in `/README.md` (keep alphabetical order!)
36 changes: 36 additions & 0 deletions projects/composition/src/app/api-data/cps-divider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"components": {
"CpsDividerComponent": {
"description": "CpsDividerComponent is a component that can be used to separate content.",
"props": {
"description": "Defines the input properties of the component.",
"values": [
{
"name": "vertical",
"optional": false,
"readonly": false,
"type": "InputSignal<boolean>",
"default": "...",
"description": "Determines whether the divider is vertically aligned."
},
{
"name": "color",
"optional": false,
"readonly": false,
"type": "InputSignal<string>",
"default": "...",
"description": "Color of the divider."
},
{
"name": "thickness",
"optional": false,
"readonly": false,
"type": "InputSignal<string | number>",
"default": "...",
"description": "Thickness of the divider, a number denoting pixels or a string."
}
]
}
}
}
}
8 changes: 8 additions & 0 deletions projects/composition/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ const routes: Routes = [
(mod) => mod.DialogPageComponent
)
},
{
matcher: pathMatcher('divider'),
title: 'Divider',
loadComponent: () =>
import('./pages/divider-page/divider-page.component').then(
(mod) => mod.DividerPageComponent
)
},
{
matcher: pathMatcher('menu'),
title: 'Menu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class NavigationSidebarComponent implements OnInit {
title: 'Dialog',
url: '/dialog'
},
{
title: 'Divider',
url: '/divider'
},
{
title: 'Expansion panel',
url: '/expansion-panel'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<app-component-docs-viewer [componentData]="componentData">
<h2 class="section-title">Horizontal divider</h2>
<div>
<p>First row</p>
<cps-divider></cps-divider>
<p>Second row</p>
</div>
<h2 class="section-title">Vertical divider</h2>
<div class="vertical-section">
<p>First column</p>
<cps-divider [vertical]="true"></cps-divider>
<p>Second column</p>
<cps-divider [vertical]="true"></cps-divider>
<p>Third column</p>
</div>
<h2 class="section-title">Custom thick and red divider</h2>
<div>
<p>First row</p>
<cps-divider thickness="4" color="red"></cps-divider>
<p>Second row</p>
</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-calm);
margin-top: 0;
}

.section-title:not(:first-child) {
margin-top: 48px;
}

.vertical-section {
display: flex;
column-gap: 12px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';
import { CpsDividerComponent } from 'cps-ui-kit';
import { ComponentDocsViewerComponent } from '../../components/component-docs-viewer/component-docs-viewer.component';

import ComponentData from '../../api-data/cps-divider.json';

@Component({
selector: 'app-divider-page',
standalone: true,
imports: [CpsDividerComponent, ComponentDocsViewerComponent],
templateUrl: './divider-page.component.html',
styleUrl: './divider-page.component.scss',
host: { class: 'composition-page' }
})
export class DividerPageComponent {
componentData = ComponentData;
}
1 change: 1 addition & 0 deletions projects/cps-ui-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Chip
- Datepicker
- Dialog
- Divider
- Expansion panel
- File upload
- Icon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CpsDividerComponent } from './cps-divider.component';

describe('CpsDividerComponent', () => {
it('should mount', () => {
cy.mount(CpsDividerComponent);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.cps-divider {
display: block;
margin: 0;

&.cps-divider-horizontal {
border-top-style: solid;
}

&.cps-divider-vertical {
border-right-style: solid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Component, ViewEncapsulation, computed, input } from '@angular/core';
import { getCSSColor } from '../../utils/colors-utils';
import { convertSize } from '../../utils/internal/size-utils';

/**
* CpsDividerComponent is a component that can be used to separate content.
* @group Components
*/
@Component({
selector: 'cps-divider',
host: {
class: 'cps-divider',
'[class.cps-divider-vertical]': 'vertical()',
'[class.cps-divider-horizontal]': '!vertical()',
'[style.border-color]': '_dividerColor()',
'[style.border-width]': '_dividerThickness()'
},
standalone: true,
template: '',
styleUrl: './cps-divider.component.scss',
encapsulation: ViewEncapsulation.None
})
export class CpsDividerComponent {
/**
* Determines whether the divider is vertically aligned.
* @group Props
*/
vertical = input(false);

/**
* Color of the divider.
* @group Props
*/
color = input('line-mid');

/**
* Thickness of the divider, a number denoting pixels or a string.
* @group Props
*/
thickness = input<number | string>('1px');

private _dividerColor = computed(() => {
return getCSSColor(this.color());
});

private _dividerThickness = computed(() => {
return convertSize(this.thickness());
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ $tbar-normal-height: 72px;
background: $row-hover-background;
}

.p-datatable .p-datatable-tbody .cps-table-row-expanded-content {
td {
border-left: 4px solid $color-surprise !important;
}
}

.p-datatable .p-datatable-tbody > tr {
background: #ffffff;
color: $body-text-color;
Expand Down Expand Up @@ -369,7 +375,10 @@ $tbar-normal-height: 72px;
color: $body-text-color;
border: 2px solid $checkbox-border-color;
border-radius: 2px;
transition: background-color 0.2s, color 0.2s, border-color 0.2s,
transition:
background-color 0.2s,
color 0.2s,
border-color 0.2s,
box-shadow 0.2s;
}

Expand Down Expand Up @@ -707,7 +716,8 @@ $tbar-normal-height: 72px;
box-sizing: border-box;
position: relative;
flex-shrink: 0;
transition: border-color 90ms cubic-bezier(0, 0, 0.2, 0.1),
transition:
border-color 90ms cubic-bezier(0, 0, 0.2, 0.1),
background-color 90ms cubic-bezier(0, 0, 0.2, 0.1);
margin-right: 8px;
opacity: 0;
Expand Down
1 change: 1 addition & 0 deletions projects/cps-ui-kit/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export * from './lib/components/cps-timepicker/cps-timepicker.component';
export * from './lib/components/cps-file-upload/cps-file-upload.component';
export * from './lib/components/cps-scheduler/cps-scheduler.component';
export * from './lib/components/cps-switch/cps-switch.component';
export * from './lib/components/cps-divider/cps-divider.component';

export * from './lib/directives/cps-tooltip/cps-tooltip.directive';

Expand Down

0 comments on commit e328bc0

Please sign in to comment.