Skip to content

Commit

Permalink
feat(table): add new table component with ag-grid
Browse files Browse the repository at this point in the history
  • Loading branch information
hirsch committed Jun 1, 2021
1 parent 0fb6fe4 commit 6c8d5bf
Show file tree
Hide file tree
Showing 24 changed files with 745 additions and 142 deletions.
1 change: 0 additions & 1 deletion docs/src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ module.exports = {
'foundation/spacing',
'foundation/responsiveness',
'foundation/footer',
'foundation/table',
'foundation/track-line',
],
},
Expand Down
119 changes: 0 additions & 119 deletions docs/src/components/foundation/table.md

This file was deleted.

16 changes: 16 additions & 0 deletions packages/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@types/autoprefixer": "^9.7.2",
"@types/jest": "^26.0.23",
"@types/puppeteer": "^5.4.2",
"ag-grid-community": "^25.2.1",
"autoprefixer": "^10.2.5",
"copyfiles": "^2.4.1",
"jest": "^26.6.3",
Expand All @@ -78,5 +79,8 @@
"puppeteer": "^5.5.0",
"rimraf": "^3.0.2"
},
"peerDependencies": {
"ag-grid-community": ">=25.2.1"
},
"gitHead": "8bb3a41da0b577e5606f49a45e588a7bd4521eca"
}
21 changes: 21 additions & 0 deletions packages/components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,12 @@ export namespace Components {
*/
"value": string;
}
interface BalTable {
/**
* If `true` the table has a full width
*/
"expanded": boolean;
}
interface BalTabs {
/**
* If `true` a acation button is added to the right
Expand Down Expand Up @@ -1625,6 +1631,12 @@ declare global {
prototype: HTMLBalTabItemElement;
new (): HTMLBalTabItemElement;
};
interface HTMLBalTableElement extends Components.BalTable, HTMLStencilElement {
}
var HTMLBalTableElement: {
prototype: HTMLBalTableElement;
new (): HTMLBalTableElement;
};
interface HTMLBalTabsElement extends Components.BalTabs, HTMLStencilElement {
}
var HTMLBalTabsElement: {
Expand Down Expand Up @@ -1720,6 +1732,7 @@ declare global {
"bal-snackbar": HTMLBalSnackbarElement;
"bal-spinner": HTMLBalSpinnerElement;
"bal-tab-item": HTMLBalTabItemElement;
"bal-table": HTMLBalTableElement;
"bal-tabs": HTMLBalTabsElement;
"bal-tag": HTMLBalTagElement;
"bal-text": HTMLBalTextElement;
Expand Down Expand Up @@ -2816,6 +2829,12 @@ declare namespace LocalJSX {
*/
"value"?: string;
}
interface BalTable {
/**
* If `true` the table has a full width
*/
"expanded"?: boolean;
}
interface BalTabs {
/**
* If `true` a acation button is added to the right
Expand Down Expand Up @@ -3085,6 +3104,7 @@ declare namespace LocalJSX {
"bal-snackbar": BalSnackbar;
"bal-spinner": BalSpinner;
"bal-tab-item": BalTabItem;
"bal-table": BalTable;
"bal-tabs": BalTabs;
"bal-tag": BalTag;
"bal-text": BalText;
Expand Down Expand Up @@ -3155,6 +3175,7 @@ declare module "@stencil/core" {
"bal-snackbar": LocalJSX.BalSnackbar & JSXBase.HTMLAttributes<HTMLBalSnackbarElement>;
"bal-spinner": LocalJSX.BalSpinner & JSXBase.HTMLAttributes<HTMLBalSpinnerElement>;
"bal-tab-item": LocalJSX.BalTabItem & JSXBase.HTMLAttributes<HTMLBalTabItemElement>;
"bal-table": LocalJSX.BalTable & JSXBase.HTMLAttributes<HTMLBalTableElement>;
"bal-tabs": LocalJSX.BalTabs & JSXBase.HTMLAttributes<HTMLBalTabsElement>;
"bal-tag": LocalJSX.BalTag & JSXBase.HTMLAttributes<HTMLBalTagElement>;
"bal-text": LocalJSX.BalText & JSXBase.HTMLAttributes<HTMLBalTextElement>;
Expand Down
20 changes: 10 additions & 10 deletions packages/components/src/components/bal-button/bal-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ export class Button implements ComponentInterface {
/**
* The name of the button, which is submitted with the form data.
*/
@Prop() name?: string = ''
@Prop() name?: string = ''

/**
* The value of the button, which is submitted with the form data.
*/
@Prop() value?: string | number = ''
@Prop() value?: string | number = ''

/**
* Emitted when the link element has clicked.
Expand Down Expand Up @@ -194,12 +194,12 @@ export class Button implements ComponentInterface {
}
}

private get iconSize() {
if (this.size === 'small') {
return 'xsmall'
}
return 'small'
}
// private get iconSize() {
// // if (this.size === 'small') {
// // return 'xsmall'
// // }
// return 'small'
// }

private get leftIconAttrs() {
if (!this.icon) {
Expand Down Expand Up @@ -283,11 +283,11 @@ export class Button implements ComponentInterface {
<TagType {...attrs} type={this.type} class={this.buttonCssClass} part="native" disabled={this.disabled} onFocus={this.onFocus} onBlur={this.onBlur} onClick={this.onClick}>
<span {...this.spanAttrs}>{/* Empty span to get the correct text height */}</span>
<bal-spinner {...this.loadingAttrs} class={this.spinnerCssClass} />
<bal-icon {...this.leftIconAttrs} class="icon-left" name={this.icon} size={this.square ? this.size : this.iconSize} color={this.color} inverted={this.isIconInverted} />
<bal-icon {...this.leftIconAttrs} class="icon-left" name={this.icon} size={this.square ? this.size : 'small'} color={this.color} inverted={this.isIconInverted} />
<bal-text {...this.spanAttrs} small={this.size === 'small'} style={{ display: this.loading ? 'none' : 'inline' }}>
<slot />
</bal-text>
<bal-icon {...this.leftRightAttrs} class="icon-right" name={this.iconRight} size={this.iconSize} color={this.color} inverted={this.isIconInverted} />
<bal-icon {...this.leftRightAttrs} class="icon-right" name={this.iconRight} size={'small'} color={this.color} inverted={this.isIconInverted} />
</TagType>
</Host>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ICellRendererComp, ICellRendererParams } from 'ag-grid-community'
import { isNil } from 'lodash'
import { ColorTypes } from '../../types/color.types'

interface BalTableButtonRendererOptions {
color?: (params: ICellRendererParams) => ColorTypes
loading?: (params: ICellRendererParams) => boolean
href?: (params: ICellRendererParams) => string
icon?: string
iconRight?: boolean
square?: boolean
expanded?: boolean
outlined?: boolean
link?: boolean
target?: '_blank' | ' _parent' | '_self' | '_top'
}

export function BalTableButtonRenderer(options: BalTableButtonRendererOptions): ICellRendererComp {
function Renderer() {}
Renderer.prototype.params = {}
Renderer.prototype.options = options

Renderer.prototype.init = function (params: ICellRendererParams): void {
this.params = params
this.element = document.createElement('bal-button')
this.element.setAttribute('size', 'small')
this.element.innerHTML = params.value
this.update()
}

Renderer.prototype.refresh = function (params: ICellRendererParams) {
this.params = params
this.update()
return true
}

Renderer.prototype.update = function () {
const color = isNil(options.color) ? '' : options.color(this.params)
this.element.setAttribute('color', color)

const loading = isNil(options.loading) ? false : options.loading(this.params)
this.element.setAttribute('loading', loading)

const href = isNil(options.href) ? undefined : options.href(this.params)
if (href) {
this.element.setAttribute('href', href)
}

this.element.setAttribute('icon', isNil(options.icon) ? '' : options.icon)
this.element.setAttribute('iconRight', isNil(options.iconRight) ? false : options.iconRight)
this.element.setAttribute('square', isNil(options.square) ? false : options.square)
this.element.setAttribute('expanded', isNil(options.expanded) ? false : options.expanded)
this.element.setAttribute('outlined', isNil(options.outlined) ? false : options.outlined)
this.element.setAttribute('link', isNil(options.link) ? false : options.link)
this.element.setAttribute('target', isNil(options.target) ? false : options.target)
}

Renderer.prototype.getGui = function () {
return this.element
}

Renderer.prototype.destroy = function () {}

return Renderer as any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ICellRendererComp, ICellRendererParams } from 'ag-grid-community'
import { isNil } from 'lodash'
import { ColorTypes } from '../../types/color.types'

interface BalTableTagRendererOptions {
color?: (params: ICellRendererParams) => ColorTypes
}

export function BalTableTagRenderer(options: BalTableTagRendererOptions): ICellRendererComp {
function Renderer() {}
Renderer.prototype.params = {}
Renderer.prototype.options = options

Renderer.prototype.init = function (params: ICellRendererParams): void {
this.params = params
this.element = document.createElement('bal-tag')
this.element.setAttribute('size', 'small')
this.element.innerHTML = params.value
this.update()
}

Renderer.prototype.refresh = function (params: ICellRendererParams) {
this.params = params
this.update()
return true
}

Renderer.prototype.update = function () {
const color = isNil(options.color) ? '' : options.color(this.params)
this.element.setAttribute('color', color)
}

Renderer.prototype.getGui = function () {
return this.element
}

Renderer.prototype.destroy = function () {}

return Renderer as any
}
Loading

0 comments on commit 6c8d5bf

Please sign in to comment.