4.2.0 • Published 8 months ago

yk-components v4.2.0

Weekly downloads
92
License
-
Repository
-
Last release
8 months ago

yk components

a set of components build with ant design.

Ant advanced table

Ant Design Table with search, select, number, datetime filter

Example:

<AdvancedTable<TestClass>
    dataSource={[]}
    size="small"
    columns={[{
        title: 'Text',
        dataIndex: 'text',
        filter: 'search',
    }, {
        title: 'Weekday',
        dataIndex: 'weekday',
        filter: 'select'
    }, {
        title: 'Amount',
        dataIndex: 'amount',
        filter: 'number'
    }, {
        title: 'Date',
        dataIndex: 'date',
        filter: 'datetime
    }]}
/>

Api

AdvancedTableProps

NameTypeRequiredDescription
dataSourceT[]trueDataSource
columnsColumnOptions\[]trueColumn configuration
defaultSelectedstring[]falseDefault selected columns
actionColumnColumnProps\falseAction column will be appended to column configuration
storageStorageConfigfalseconfigure if settings should be save to local storage
Ant Table Props......

ColumnOptions\

NameTypeRequiredDescription
titlestringtruecolumn title
dataIndexstringtruecolumn identifier, must be unique
hiddenbooleanfalseDefault: false
sorterfalsefalsesorter for column, Default: true
filter"select""search""number""datetime"falsefilter for column
value(r: T) => anyfalsevalue selector, Default: get(record, dataIndex)
renderToString(v: any, record: T, i: number) => stringfalserender value as string for export and select
Ant Column Props......

AsyncButton

Displays loading spinner when onClick returns a Promise

Example:

<AsyncButton {...defaultAntButtonProps} />

Advanced Form

Form Items for Ant Desing Form

Example:

<AdvancedForm
    onSubmit={handleSave}
    initialValues={{
        text: 'text',
        number: 10,
        date: moment(new Date()),
        dateTime: moment(new Date()),
        time: moment(new Date()),
        select: true,
        custom: true
    }}
>
    <AdvancedForm.Group
        items={[{
            title: 'Text',
            type: 'string',
            dataIndex: 'text',
            rules: [{ required: true }]
        }, {
            type: 'number',
            title: 'Number',
            dataIndex: 'number',
            format: '0.0,0'
        }, {
            type: 'date',
            title: 'Date',
            dataIndex: 'date',
            variant: 'date'
        }, {
            type: 'date',
            title: 'Time',
            dataIndex: 'time',
            variant: 'time'
        }, {
            type: 'date',
            title: 'Date Time',
            dataIndex: 'dateTime',
            variant: 'dateTime'
        }, {
            type: 'select',
            title: 'Select',
            dataIndex: 'select',
            options: [
                { value: true, label: 'Ja' },
                { value: false, label: 'Nein' }
            ]
        }, {
            type: 'radio',
            title: 'Radio',
            dataIndex: 'radio',
            options: [
                { value: true, label: 'Ja' },
                { value: false, label: 'Nein' }
            ]
        }, {
            type: 'custom-updatable',
            shouldUpdate: (prev, next) => prev.custom !== next.custom,
            render: () => <Form.Item
                name="custom"
                valuePropName="checked"
                children={<Checkbox>Custom</Checkbox>}
            />
        }]}
    />
</AdvancedForm>

Api

AdvancedFormProps\

NameTypeRequiredDefault
onSubmit(values: any) => Promise\falseundefined
initialValuesTfalseundefined
cancelTextstringfalse'Cancel'
submitTextstringfalse'Save'
onCancel() => voidfalseundefined
showButtonsbooleanfalsetrue

FormItemOptions

BaseFormProps
NameTypeRequiredDescription
titlestringtrueTitle of form item
dataIndexstringstring[]truename of property
hiddenbooleanfalseis item hidden
rulesRule[]falsevalidation rules
styleReact.CSSPropertiesfalsecustom css
FormStringProps
NameTypeRequiredDescription
textarea{ row?: number; } | truefalseshould input be displayed as textarea
FormNumberProps
NameTypeRequiredDescription
precisionnumberfalsepercision of number
FormSelectProps
NameTypeRequiredDescription
options{ value: any; label: React.ReactNode; }[]trueselect options
FormCheckboxProps
NameTypeRequiredDescription
checkboxTextReact.ReactNodefalsetext displayed next to checkbox
FormSwitchProps
NameTypeRequiredDescription
trueTextReact.ReactNodefalsetext display when switch is active
falseTextReact.ReactNodefalsetext display when switch is not active
FormRadioProps
NameTypeRequiredDescription
options{ value: any; label: React.ReactNode; }[]trueradio options;
variant"button" | "checkbox"falseDefault: "button"
FormDateProps
NameTypeRequiredDescription
variant"date" | "time" | "dateTime"falsevariant of date, default: "date"
FormCustomProps
NameTypeRequiredDescription
render() => React.ReactElementtruerender function
FormCustomUpdatableProps
NameTypeRequiredDescription
shouldUpdate(prev: any, next: any) => booleantrueshould update check funktion
render(instance: FormInstance) => React.ReactElementtruerender function

Formatter

Date Formatter

set global config

dateFormatter.configure(options: Partial<DateFormatterConfig>): void;

get format for type

dateFormatter.getFormat(type: "date" | "time" | "dateTime" | string): string;

format number

dateFormatter.format(val: any, type: "date" | "time" | "dateTime" | string = "date"): string;

DateFormatterConfig

NameTypeDefault
emptyValuestring-
typesRecord<string,string>falsedate: "DD.MM.YYYY", time: "HH:mm", dateTime: "DD.MM. YYYY - HH:mm"

Number Formatter

set global config

numberFormatter.configure(options: Partial<NumberFormatterConfig>): void;

get item from config

numberFormatter.getConfig(key: keyof NumberFormatterConfig): string;

format number

numberFormatter.format(val: any, percision: number = 3): string;

trim zero at end

numberFormatter.trim(val: string): string;

parse formatted number

numberFormatter.parse(val: any): number;

NumberFormatterConfig

NameTypeDefault
decimalSeparatorstring.
thousandsSeparatorstring,
emptyValuestring-

ThemeProvider

Theme Provider for Ant Design

Example:

<ThemeProvider
    defaultTheme="dark"
    themes={{
        dark: ["/antd.dark.min.css", "/scrollbar.dark.css"],
        light: ["/antd.min.css", "/scrollbar.light.css"]
    }}
    themeVariables={{
        light: {
            primary: '#69c0ff'
        },
        dark: {
            primary: '#164c7e'
        }
    }}
    spinner={<h1 style={{ margin: 'auto 100px' }} children="Loading..." />}
>
    {children}
</ThemeProvider>

Api

NameTypeRequiredDescription
themesRecord<string, string | string[]>truetheme name to url mapping, multiple urls are supported
themeVariablesRecord<keyof T, Record\<string,string>>falsetheme variables
defaultThemestringtruedefault theme
spinnerReact.ReactNodetrueloading spinner for theme change
childrenReact.ReactNodetruechildren of theme context

CSS

  • i have created styles for scrollbars in chrome, dark an light variant.
  • build/css/scrollbar.light.css
  • build/css/scrollbar.dark.css

Commands

Start storybook

yarn start

Build

yarn build
4.2.0

8 months ago

4.1.2

1 year ago

3.2.6

2 years ago

3.2.5

2 years ago

4.0.0

2 years ago

3.2.7

2 years ago

4.1.0

1 year ago

4.1.1

1 year ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.10

3 years ago

2.1.9

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.4

3 years ago

2.1.5

3 years ago

2.1.2

3 years ago

2.1.3

3 years ago

2.1.1

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.1.0

3 years ago

1.3.10

3 years ago

1.3.9

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.8

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.11

3 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.10

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.0

4 years ago