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

Add TreeSelect to storybook #28666

Merged
merged 15 commits into from
May 29, 2024
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
46 changes: 19 additions & 27 deletions core-web/apps/dotcms-ui/src/stories/primeng/data/Tree.stories.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
// also exported from '@storybook/angular' if you can deal with breaking changes in 6.1
import { Meta, moduleMetadata, Story } from '@storybook/angular';
import { TreeNode } from 'primeng/api';
import { Tree, TreeModule } from 'primeng/tree';

import { TreeModule } from 'primeng/tree';
import type { Meta, StoryObj } from '@storybook/angular';

export default {
const meta: Meta<Tree> = {
title: 'PrimeNG/Data/Tree',
decorators: [
moduleMetadata({
imports: [TreeModule]
})
],
component: Tree,
parameters: {
layout: 'centered',
docs: {
description: {
component:
'Paginator is a generic component to display content in paged format.: https://primefaces.org/primeng/showcase/#/paginator'
'Tree is used to display hierarchical data: https://www.primefaces.org/primeng-v15-lts/tree'
}
}
}
} as Meta;
};
export default meta;

type Story = StoryObj<Tree>;

const files = [
export const files: TreeNode[] = [
{
label: 'Documents',
data: 'Documents Folder',
Expand Down Expand Up @@ -102,21 +101,14 @@ const files = [
}
];

const BasicTemplate = `<p-tree [value]="files"></p-tree>`;

export const Basic: Story = () => {
return {
template: BasicTemplate,
export const Default: Story = {
render: () => ({
moduleMetadata: {
imports: [TreeModule]
},
props: {
files
}
};
};

Basic.parameters = {
docs: {
source: {
code: BasicTemplate
}
}
},
template: `<p-tree [value]="files"></p-tree>`
})
};
59 changes: 23 additions & 36 deletions core-web/apps/dotcms-ui/src/stories/primeng/form/Chips.stories.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,41 @@
import { Meta, moduleMetadata, Story } from '@storybook/angular';
import { Meta, StoryObj } from '@storybook/angular';

import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { Chips, ChipsModule } from 'primeng/chips';

export default {
const meta: Meta = {
title: 'PrimeNG/Form/Chips',
component: Chips,
parameters: {
docs: {
description: {
component:
'Chips is used to enter multiple values on an input field: https://primeng.org/checkbox'
'Chips is used to enter multiple values on an input field: https://primeng.org/chips'
}
}
},
decorators: [
moduleMetadata({
imports: [ChipsModule, BrowserAnimationsModule]
})
],
argTypes: {
values: {
name: 'values',
description: 'Array of strings, each representing a chip.'
}
},
args: {
values: ['first']
}
} as Meta;

const ChipsTemplate = `<p-chips [(ngModel)]="values" ></p-chips>`;

const Template: Story<Chips> = (props: Chips) => {
const template = ChipsTemplate;

return {
props,
template
};
};

export const Basic: Story = Template.bind({});

Basic.argTypes = {
values: {
name: 'values',
description: 'Array of strings, each representing a chip.'
values: ['one', 'two']
}
};

Basic.parameters = {
docs: {
source: {
code: ChipsTemplate
}
}
export default meta;

type Story = StoryObj<Chips>;

export const Default: Story = {
render: (args) => ({
props: args,
moduleMetadata: {
imports: [ChipsModule, BrowserAnimationsModule, FormsModule]
},
template: `<p-chips [(ngModel)]="values" />`
})
};
231 changes: 231 additions & 0 deletions core-web/apps/dotcms-ui/src/stories/primeng/form/TreeSelect.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import { Meta, StoryObj } from '@storybook/angular';

import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { TreeSelectModule, TreeSelect } from 'primeng/treeselect';

import { files } from './../data/Tree.stories';

const meta: Meta<TreeSelect> = {
title: 'PrimeNG/Form/TreeSelect',
component: TreeSelect,
parameters: {
layout: 'centered',
docs: {
description: {
component:
'TreeSelect is a form component to choose from hierarchical data.: https://www.primefaces.org/primeng-v15-lts/treeselect'
}
}
}
};
export default meta;

type Story = StoryObj<TreeSelect>;

const storyConfigBase: Partial<Story['render']> = {
moduleMetadata: {
imports: [TreeSelectModule, FormsModule, BrowserAnimationsModule, BrowserModule]
},
props: {
files,
selectedNodes: ''
}
};

export const Default: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<p-treeSelect
[(ngModel)]="selectedNodes"
class="md:w-20rem w-full" containerStyleClass="w-full"
[options]="files"
placeholder="Select Item"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
</p-treeSelect>
</div>
`
})
};

export const Invalid: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<p-treeSelect
class="md:w-20rem w-full ng-invalid ng-dirty"
containerStyleClass="w-full"
[(ngModel)]="selectedNodes"
[options]="files"
placeholder="Select Item"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
</p-treeSelect>
</div>
`
})
};

export const WithLabel: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<span class="md:w-20rem w-full">
<label for="treeselect">Label</label>
<p-treeSelect
containerStyleClass="w-full"
[(ngModel)]="selectedNodes"
[options]="files"
placeholder="Select Item"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
</p-treeSelect>
</span>
</div>
`
})
};

export const WithFloatLabel: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<div class="md:w-20rem w-full">
<span class="p-float-label w-full">
<p-treeSelect
containerStyleClass="w-full"
[(ngModel)]="selectedNodes"
[options]="files"
placeholder="Select Item"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
</p-treeSelect>
<label for="treeselect">Float Label</label>
</span>
</div>
</div>
`
})
};

export const Disable: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<p-treeSelect
[disabled]="true"
[(ngModel)]="selectedNodes"
class="md:w-20rem w-full" containerStyleClass="w-full"
[options]="files"
placeholder="Select Item"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
</p-treeSelect>
</div>
`
})
};

export const Multiple: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<p-treeSelect
class="w-full md:w-20rem"
containerStyleClass="w-full"
[(ngModel)]="selectedNodes"
[options]="files"
[metaKeySelection]="false"
selectionMode="multiple"
placeholder="Select Item"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
</p-treeSelect>
</div>
`
})
};

export const Checkbox: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<p-treeSelect
class="w-full md:w-20rem"
containerStyleClass="w-full"
[(ngModel)]="selectedNodes"
[options]="files"
[showClear]="true"
display="chip"
[metaKeySelection]="false"
selectionMode="checkbox"
placeholder="Select Item"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
</p-treeSelect>
</div>
`
})
};

export const Filter: Story = {
render: () => ({
...storyConfigBase,
template: `
<div class="card flex justify-content-center w-25rem h-25rem">
<p-treeSelect
class="md:w-20rem w-full"
containerStyleClass="w-full"
[(ngModel)]="selectedNodes"
[options]="files"
placeholder="Select Item"
[filter]="true"
[filterInputAutoFocus]="true"
[showClear]="true"
>
<ng-template pTemplate="triggericon">
<i class="pi pi-chevron-down"></i>
</ng-template>
<ng-template pTemplate="filtericon">
<i class="pi pi-search"></i>
</ng-template>
<ng-template pTemplate="closeicon">
<i class="pi pi-times"></i>
</ng-template>
</p-treeSelect>
</div>
`
})
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}

.p-tree .p-tree-container .p-treenode {
padding: 0.25rem;
padding: $spacing-0;
}

.p-tree .p-tree-container .p-treenode .p-treenode-content {
Expand Down
Loading
Loading