Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
FLOW-968 align property introduced on f-tcell. (#202)
Browse files Browse the repository at this point in the history
* FLOW-968 align property added on f-tcell

* FLOW-968 align property added on f-tcell
  • Loading branch information
vikas-cldcvr authored Nov 29, 2023
1 parent 3073433 commit ecda224
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 55 deletions.
2 changes: 1 addition & 1 deletion packages/flow-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For a new project, Flow has put together starter kits with basic dependencies to
- [Aungular](https://github.com/cldcvr/flow-starterkit-angular)
- [React](https://github.com/cldcvr/flow-starterkit-react)

If you would like to contribute to an existing starter kit or write a new one for a different framework, write to <flow@cldcvr.com> or ping on our slack channel.
If you would like to contribute to an existing starter kit or write a new one for a different framework, write to <flow@ollion.com> or ping on our slack channel.

**VScode Plugin**: [Install Flow's Plugin](https://marketplace.visualstudio.com/items?itemName=dev-vikas.flow-intellisense-vscode) to access components, icons, values, etc, and documentation inside of VScode.

Expand Down
6 changes: 6 additions & 0 deletions packages/flow-table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Change Log

## [2.2.0] - 2023-11-28

### Minor Changes

- `align` property introduced on `f-tcell`.

## [2.1.0] - 2023-11-28

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-table/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cldcvr/flow-table",
"version": "2.1.0",
"version": "2.2.0",
"description": "Table component for flow library",
"module": "dist/flow-table.es.js",
"main": "dist/flow-table.cjs.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { html, HTMLTemplateResult, nothing, PropertyValueMap, unsafeCSS } from "
import { ifDefined } from "lit-html/directives/if-defined.js";
import { property, query, state } from "lit/decorators.js";
import { FTable, FTableSelectable, FTableSize, FTableVariant } from "../f-table/f-table";
import { FTcell, FTcellActions } from "../f-tcell/f-tcell";
import { FTcell, FTcellActions, FTcellAlign } from "../f-tcell/f-tcell";
import { FTrow, FTrowChevronPosition, FTrowState } from "../f-trow/f-trow";
import eleStyle from "./f-table-schema.scss?inline";
import globalStyle from "./f-table-schema-global.scss?inline";
Expand All @@ -32,6 +32,7 @@ export type FTableSchemaData = {
export type FTableSchemaCell<T = any> = {
value: T;
actions?: FTcellActions;
align?: FTcellAlign;
template?: (highlightText?: string | null) => HTMLTemplateResult;
toString?: () => string;
};
Expand All @@ -40,6 +41,7 @@ export type FTableSchemaHeaderCell<T = any> = {
value: T;
template?: () => HTMLTemplateResult;
width?: string;
align?: FTcellAlign;
selected?: boolean;
disableSort?: boolean;
sticky?: boolean;
Expand Down Expand Up @@ -185,6 +187,7 @@ export class FTableSchema extends FRoot {
part="cell"
.selected=${selected}
.width=${width}
.align=${columnHeader[1].align}
?sticky-left=${ifDefined(sticky)}
?sticky-top=${ifDefined(this.stickyHeader)}
@selected-column=${this.handleColumnSelection}
Expand Down Expand Up @@ -249,6 +252,7 @@ export class FTableSchema extends FRoot {
.selected=${selected}
.width=${width}
.actions=${actions}
.align=${cell.align}
?sticky-left=${ifDefined(sticky)}
>${this.getCellTemplate(row.data[columnHeader[0]], highlightTerm)}
</f-tcell>`;
Expand Down Expand Up @@ -537,7 +541,7 @@ export class FTableSchema extends FRoot {
return cell.template(highlightTerm);
}

return html`<f-text style="height:100%" .highlight=${highlightTerm}>${cell.value}</f-text>`;
return html`<f-text .highlight=${highlightTerm}>${cell.value}</f-text>`;
}

handleColumnSelection(e: CustomEvent) {
Expand Down
15 changes: 9 additions & 6 deletions packages/flow-table/src/components/f-table/f-table-global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ f-table {
}

&[variant="bordered"] {
border-top: 1px solid var(--color-border-default);
border-left: 1px solid var(--color-border-default);
border-right: 1px solid var(--color-border-default);

> f-trow {
--border-bottom: 1px solid var(--color-border-default);
--border-left: 1px solid var(--color-border-default);
&:first-child {
> f-tcell {
border-top: 1px solid var(--color-border-default);
}
}
> f-tcell {
&:not(:last-child) {
border-right: 1px solid var(--color-border-default);
border-right: 1px solid var(--color-border-default);

&:first-child {
border-left: 1px solid var(--color-border-default);
}
border-bottom: 1px solid var(--color-border-default);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/flow-table/src/components/f-tcell/f-tcell.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
.cell-radio {
display: var(--display-cell-radio);
}
.details-toggle {
margin-left: auto;
}

.f-tcell-wrapper {
display: flex;
justify-content: flex-start;
Expand All @@ -20,5 +18,8 @@
.row-toggler.left {
margin-right: 12px;
}
.f-tcell-content {
flex: 1 1;
}
}
}
68 changes: 42 additions & 26 deletions packages/flow-table/src/components/f-tcell/f-tcell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export type FTcellAction = {

export type FTcellActions = FTcellAction[];

export type FTcellAlign =
| "top-left"
| "top-center"
| "top-right"
| "middle-left"
| "middle-center"
| "middle-right"
| "bottom-left"
| "bottom-center"
| "bottom-right";

@flowElement("f-tcell")
export class FTcell extends FRoot {
/**
Expand Down Expand Up @@ -49,6 +60,9 @@ export class FTcell extends FRoot {
@property({ type: String, reflect: true })
width?: string;

@property({ type: String, reflect: true })
align?: FTcellAlign = "top-left";

@state()
selectable?: FTableSelectable = "none";

Expand Down Expand Up @@ -107,37 +121,39 @@ export class FTcell extends FRoot {

render() {
return html`<div class="f-tcell-wrapper">
${this.selectable === "multiple"
? html`<f-checkbox
?disabled=${this.isDisabled}
@input=${this.handleSelection}
></f-checkbox>`
: nothing}
${this.selectable === "single"
? html`<f-radio
?disabled=${this.isDisabled}
@input=${this.handleSelection}
class="cell-radio"
></f-radio>`
: nothing}
${this.expandIcon && this.expandIconPosition === "left"
? html`
<f-icon-button
size="medium"
category="packed"
class="row-toggler left"
state="neutral"
@click=${this.toggleDetails}
icon="i-chevron-down"
></f-icon-button>
`
: nothing}<slot></slot>
<f-div .align=${this.align} height="100%" class="f-tcell-content">
${this.selectable === "multiple"
? html`<f-checkbox
?disabled=${this.isDisabled}
@input=${this.handleSelection}
></f-checkbox>`
: nothing}
${this.selectable === "single"
? html`<f-radio
?disabled=${this.isDisabled}
@input=${this.handleSelection}
class="cell-radio"
></f-radio>`
: nothing}
${this.expandIcon && this.expandIconPosition === "left"
? html`
<f-icon-button
size="medium"
category="packed"
class="row-toggler left"
state="neutral"
@click=${this.toggleDetails}
icon="i-chevron-down"
></f-icon-button>
`
: nothing}<slot></slot>
</f-div>
<f-div
class="details-toggle"
height="100%"
width="hug-content"
gap="medium"
align="middle-right"
.align=${this.align ?? "middle-right"}
>
${this.renderActions()}
${this.expandIcon && this.expandIconPosition === "right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export default {
};

export const Playground = {
render: args => {
render: (args: Record<string, unknown>) => {
return html`
<f-table>
<f-trow slot="header">
${[1, 2, 3].map(cellNumber => {
return html`<f-tcell> Header ${cellNumber} </f-tcell>`;
})}
</f-trow>
${[1, 2, 3].map(rowNumber => {
${[1, 2, 3].map(() => {
return html`<f-trow>
${[1, 2, 3].map(cellNumber => {
return html`<f-tcell .actions=${args.actions}>
Expand Down Expand Up @@ -74,7 +74,7 @@ export const Anatomy = {
};

export const Actions = {
render: args =>
render: () =>
html`<f-div direction="column" state="subtle" padding="small" gap="large">
<f-text>3rd column has actions</f-text>
<f-table>
Expand All @@ -83,7 +83,7 @@ export const Actions = {
return html`<f-tcell> Header ${cellNumber} </f-tcell>`;
})}
</f-trow>
${[1, 2, 3].map(rowNumber => {
${[1, 2, 3].map(() => {
return html`<f-trow>
${[1, 2, 3].map(cellNumber => {
return html`<f-tcell
Expand Down Expand Up @@ -116,10 +116,10 @@ export const Actions = {
};

export const Selected = {
render: args =>
render: () =>
html`<f-div direction="column" state="subtle" padding="small" gap="large"
>${[true].map(
selected =>
() =>
html`<f-text>2nd column is selected</f-text
><f-table>
<f-trow slot="header">
Expand All @@ -129,7 +129,7 @@ export const Selected = {
</f-tcell>`;
})}
</f-trow>
${[1, 2, 3].map(rowNumber => {
${[1, 2, 3].map(() => {
return html`<f-trow>
${[1, 2, 3].map(cellNumber => {
return html`<f-tcell .selected=${cellNumber === 2}>
Expand All @@ -145,19 +145,59 @@ export const Selected = {
name: "selected"
};

export const Align = {
render: () => {
const alignValues = [
"top-left",
"top-center",
"top-right",
"middle-left",
"middle-center",
"middle-right",
"bottom-left",
"bottom-center",
"bottom-right"
];
return html`<f-div padding="x-large"
><f-table variant="bordered">
<f-trow slot="header">
${alignValues.map(align => {
return html`<f-tcell width="300px" .align=${align}> ${align} </f-tcell>`;
})}
<f-tcell> Cell with height </f-tcell>
</f-trow>
${[1, 2, 3].map(() => {
return html`<f-trow>
${alignValues.map(align => {
return html`<f-tcell .align=${align}>
<f-text inline> align="${align}" </f-text>
</f-tcell>`;
})}
<f-tcell>
<f-div height="200px"></f-div>
</f-tcell>
</f-trow>`;
})}
</f-table></f-div
>`;
},

name: "align"
};

export const HighlightColumn = {
render: args => {
render: () => {
const fieldRef = createRef();

const highlightColumnHandler = event => {
const highlightColumnHandler = (event: CustomEvent) => {
if (fieldRef.value) {
fieldRef.value.textContent = JSON.stringify(event.detail, undefined, 2);
}
};

return html`<f-div direction="column" state="subtle" padding="small" gap="large"
>${[true].map(
selected =>
() =>
html`<f-text>Hover on header cell, it will trigger 'highlight-column' event </f-text>
<f-table>
<f-trow slot="header">
Expand All @@ -170,7 +210,7 @@ export const HighlightColumn = {
</f-tcell>`;
})}
</f-trow>
${[1, 2, 3].map(rowNumber => {
${[1, 2, 3].map(() => {
return html`<f-trow>
${[1, 2, 3].map(cellNumber => {
return html`<f-tcell .selected=${cellNumber === 2}>
Expand All @@ -193,18 +233,18 @@ export const HighlightColumn = {
};

export const SelectedColumn = {
render: args => {
render: () => {
const fieldRef = createRef();

const selectedColumnHandler = event => {
const selectedColumnHandler = (event: CustomEvent) => {
if (fieldRef.value) {
fieldRef.value.textContent = JSON.stringify(event.detail, undefined, 2);
}
};

return html`<f-div direction="column" state="subtle" padding="small" gap="large"
>${[true].map(
selected =>
() =>
html`<f-text>Click on header cell, it will trigger 'selected-column' event </f-text>
<f-table>
<f-trow slot="header">
Expand All @@ -217,7 +257,7 @@ export const SelectedColumn = {
</f-tcell>`;
})}
</f-trow>
${[1, 2, 3].map(rowNumber => {
${[1, 2, 3].map(() => {
return html`<f-trow>
${[1, 2, 3].map(cellNumber => {
return html`<f-tcell .selected=${cellNumber === 2}>
Expand Down
5 changes: 4 additions & 1 deletion stories/utils/mock-users-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export default function getFakeUsers(rowCount = 100, columnCount = 8): FTableSch
const users = [];

for (let i = 0; i < rowCount; i++) {
const firstName = { value: faker.name.firstName() };
const firstName: FTableSchemaCell<string> = {
value: faker.name.firstName(),
align: "middle-left"
};
const lastName = {
value: faker.name.lastName(),
template: function () {
Expand Down

0 comments on commit ecda224

Please sign in to comment.