Skip to content

Commit

Permalink
feat(common)!: migrate from Flatpickr to Vanilla-Calendar (#1466)
Browse files Browse the repository at this point in the history
* feat!: migrate from Flatpickr to Vanilla-Calendar
  • Loading branch information
ghiscoding authored Apr 27, 2024
1 parent 12661a3 commit fb6e950
Show file tree
Hide file tree
Showing 75 changed files with 1,142 additions and 1,397 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"javascript",
"typescript"
],
"typescript.format.semicolons": "insert"
"typescript.format.semicolons": "insert",
"typescript.tsdk": "node_modules\\typescript\\lib"
}
1 change: 1 addition & 0 deletions docs/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [Editors](column-functionalities/Editors.md)
* [new Autocomplete (Kraaden-lib)](column-functionalities/editors/Autocomplete-Editor-(Kraaden-lib).md)
* [Date Picker (flatpickr)](column-functionalities/editors/Date-Editor-(flatpickr).md)
* [Date Picker (vanilla-calendar)](column-functionalities/editors/date-editor-(vanilla-calendar).md)
* [LongText (textarea)](column-functionalities/editors/LongText-Editor-(textarea).md)
* [Select Dropdown Editor (single/multiple)](column-functionalities/editors/Select-Dropdown-Editor-(single,multiple).md)
* [Filters](column-functionalities/filters/README.md)
Expand Down
12 changes: 6 additions & 6 deletions docs/column-functionalities/Editors.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ this.columnDefinitions = [
];
```

So to make it more clear, the `saveOutputType` is the format that will be sent to the `onCellChange` event, then the `outputType` is how the date will show up in the date picker (Flatpickr) and finally the `type` is basically the input format (coming from your dataset). Note however that each property are cascading, if 1 property is missing it will go to the next one until 1 is found... for example, on the `onCellChange` if you aren't defining `saveOutputType`, it will try to use `outputType`, if again none is provided it will try to use `type` and finally if none is provided it will use `FieldType.dateIso` as the default.
So to make it more clear, the `saveOutputType` is the format that will be sent to the `onCellChange` event, then the `outputType` is how the date will show up in the date picker (Vanilla-Calendar) and finally the `type` is basically the input format (coming from your dataset). Note however that each property are cascading, if 1 property is missing it will go to the next one until 1 is found... for example, on the `onCellChange` if you aren't defining `saveOutputType`, it will try to use `outputType`, if again none is provided it will try to use `type` and finally if none is provided it will use `FieldType.dateIso` as the default.

## Perform an action After Inline Edit
#### Recommended way
Expand Down Expand Up @@ -201,9 +201,9 @@ Some of the Editors could receive extra options, which is mostly the case for Ed
```ts
this.columnDefinitions = [{
id: 'start', name: 'Start Date', field: 'start',
editor: {
editor: {
model: Editors.date,
editorOptions: { minDate: 'today' }
editorOptions: { range: { min: 'today' } } as VanillaCalendarOption
}
}];
```
Expand All @@ -213,10 +213,10 @@ You could also define certain options as a global level (for the entire grid or

```ts
this.gridOptions = {
defaultEditorOptions: {
defaultEditorOptions: {
autocompleter: { debounceWaitMs: 150 }, // typed as AutocompleterOption
date: { minDate: 'today' },
longText: { cols: 50, rows: 5 }
date: { range: { min: 'today' } },
longText: { cols: 50, rows: 5 }
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ You could also define certain options as a global level (for the entire grid or

```ts
this.gridOptions = {
defaultEditorOptions: {
date: { minDate: 'today' }, // typed as FlatpickrOption
defaultEditorOptions: {
date: { range: { min: 'today' } }, // typed as FlatpickrOption
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
##### index
- [Editor Options](#editor-options)
- [Custom Validator](#custom-validator)
- See the [Editors - Wiki](../Editors.md) for more general info about Editors (validators, event handlers, ...)

### Information
The Date Editor is provided through an external library named [Vanilla-Calendar-Picker](https://github.com/ghiscoding/vanilla-calendar-picker) (a fork of [Vanilla-Calendar-Pro](https://vanilla-calendar.pro)) and all options from that library can be added to your `editorOptions` (see below), so in order to add things like minimum date, disabling dates, ... just review all the [Vanilla-Calendar-Pro](https://vanilla-calendar.pro/docs/reference/additionally/settings) and then add them into `editorOptions`. Also just so you know, `editorOptions` is use by all other editors as well to expose external library like Autocompleter, Multiple-Select, etc...

### Demo
[Demo Page](https://ghiscoding.github.io/slickgrid-universal/#/example12) | [Demo Component](https://github.com/ghiscoding/slickgrid-universal/blob/master/examples/webpack-demo-vanilla-bundle/src/examples/example12.ts)

### Editor Options
You can use any of the Vanilla-Calendar [settings](https://vanilla-calendar.pro/docs/reference/additionally/settings) by adding them to `editorOptions` as shown below.

> **Note** for easier implementation, you should import `VanillaCalendarOption` from Slickgrid-Universal common package.
```ts
import { type VanillaCalendarOption } from '@slickgrid-universal/common';

prepareGrid() {
this.columnDefinitions = [
{
id: 'title', name: 'Title', field: 'title',
editor: {
model: Editors.date,
editorOptions: {
range: {
max: 'today',
disabled: ['2022-08-15', '2022-08-20'],
}
} as VanillaCalendarOption,
},
},
];
}
```

#### Grid Option `defaultEditorOptions
You could also define certain options as a global level (for the entire grid or even all grids) by taking advantage of the `defaultEditorOptions` Grid Option. Note that they are set via the editor type as a key name (`autocompleter`, `date`, ...) and then the content is the same as `editorOptions` (also note that each key is already typed with the correct editor option interface), for example

```ts
this.gridOptions = {
defaultEditorOptions: {
date: { range: { min: 'today' } }, // typed as VanillaCalendarOption
}
}
```

### Custom Validator
You can add a Custom Validator from an external function or inline (inline is shown below and comes from [Example 12](https://ghiscoding.github.io/slickgrid-universal/#/example12))
```ts
initializeGrid() {
this.columnDefinitions = [
{
id: 'title', name: 'Title', field: 'title',
editor: {
model: Editors.date,
required: true,
validator: (value, args) => {
const dataContext = args && args.item;
if (dataContext && (dataContext.completed && !value)) {
return { valid: false, msg: 'You must provide a "Finish" date when "Completed" is checked.' };
}
return { valid: true, msg: '' };
}
},
},
];
}
```
21 changes: 10 additions & 11 deletions docs/column-functionalities/filters/Compound-Filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
- [SASS Styling](#sass-styling)
- [Compound Input Filter](#how-to-use-compoundinput-filter)
- [Compound Date Filter](#how-to-use-compounddate-filter)
- [Filter Options (`FlatpickrOption` interface)](#filter-options-flatpickroption-interface)
- [Compound Operator List (custom list)](#compound-operator-list-custom-list)
- [Compound Operator Alternate Texts](#compound-operator-alternate-texts)
- [Filter Complex Object](../Input-Filter.md#how-to-filter-complex-objects)
- [Update Filters Dynamically](../Input-Filter.md#update-filters-dynamically)
- [How to avoid filtering when only Operator dropdown is changed?](#how-to-avoid-filtering-when-only-operator-dropdown-is-changed)

### Description
Compound filters are a combination of 2 elements (Operator Select + Input Filter) used as a filter on a column. This is very useful to make it obvious to the user that there are Operator available and even more useful with a date picker (`Flatpickr`).
Compound filters are a combination of 2 elements (Operator Select + Input Filter) used as a filter on a column. This is very useful to make it obvious to the user that there are Operator available and even more useful with a date picker (`Vanilla-Calendar`).

### Demo
[Demo Page](https://ghiscoding.github.io/slickgrid-universal/#/example02) / [Demo Component](https://github.com/ghiscoding/slickgrid-universal/blob/master/examples/webpack-demo-vanilla-bundle/src/examples/example02.ts)
Expand All @@ -21,11 +20,11 @@ There are multiple types of compound filters available
1. `Filters.compoundInputText` adds an Operator combine to an Input of type `text` (alias to `Filters.compoundInput`).
2. `Filters.compoundInputNumber` adds an Operator combine to an Input of type `number`.
3. `Filters.compoundInputPassword` adds an Operator combine to an Input of type `password.
4. `Filters.compoundDate` adds an Operator combine to a Date Picker (flatpickr).
4. `Filters.compoundDate` adds an Operator combine to a Date Picker (Vanilla-Calendar).
5. `Filters.compoundSlider` adds an Operator combine to a Slider Filter.

### SASS Styling
You can change the `$flatpickr-bgcolor` and any of the `$compound-filter-X` SASS [variables](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/styles/_variables.scss#L660) for styling. For more info on how to use SASS in your project, read the [Wiki - Styling](../../styling/styling.md)
You can change some of the SASS [variables](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/styles/_variables.scss#L648) for styling. For more info on how to use SASS in your project, read the [Wiki - Styling](../../styling/styling.md)

### How to use CompoundInput Filter
Simply set the flag `filterable` to True and use the filter type `Filters.compoundInput`. Here is an example with a full column definition:
Expand Down Expand Up @@ -125,15 +124,15 @@ this.gridOptions = {
};
```

#### Filter Options (`FlatpickrOption` interface)
All the available options that can be provided as `filterOptions` to your column definitions can be found under this [FlatpickrOption interface](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/interfaces/flatpickrOption.interface.ts) and you should cast your `filterOptions` to that interface to make sure that you use only valid options of the [Flatpickr](https://flatpickr.js.org/) library.
#### Filter Options (`VanillaCalendarOption` interface)
All the available options that can be provided as `filterOptions` to your column definitions can be found under this [VanillaCalendarOption interface](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/interfaces/vanillaCalendarOption.interface.ts) and you should cast your `filterOptions` with the expected interface to make sure that you use only valid settings of the [Vanilla-Calendar](https://vanilla-calendar.pro/docs/reference/additionally/settings) library.

```ts
filter: {
model: Filters.compoundDate,
filterOptions: {
minDate: 'today'
} as FlatpickrOption
range: { min: 'today' }
} as VanillaCalendarOption
}
```

Expand All @@ -142,10 +141,10 @@ You could also define certain options as a global level (for the entire grid or

```ts
this.gridOptions = {
defaultFilterOptions: {
defaultFilterOptions: {
// Note: that `date`, `select` and `slider` are combining both compound & range filters together
date: { minDate: 'today' },
select: { minHeight: 350 }, // typed as MultipleSelectOption
date: { range: { min: 'today' } }, // typed as VanillaCalendarOption
select: { minHeight: 350 }, // typed as MultipleSelectOption
slider: { sliderStartValue: 10 }
}
}
Expand Down
29 changes: 15 additions & 14 deletions docs/column-functionalities/filters/Range-Filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
- [Using a Slider Range](#using-a-slider-range-filter)
- [Filter Options](#filter-options)
- [Using a Date Range](#using-a-date-range-filter)
- [Filter Options (`FlatpickrOption` interface)](#filter-options-flatpickroption-interface)
- [Update Filters Dynamically](Input-Filter.md#update-filters-dynamically)

### Introduction
Range filters allows you to search for a value between 2 min/max values, the 2 most common use case would be to filter between 2 numbers or dates, you can do that with the new Slider & Date Range Filters. The range can also be defined as inclusive (`>= 0 and <= 10`) or exclusive (`> 0 and < 10`), the default is exclusive but you can change that, see below for more info.
Range filters allows you to search for a value between 2 min/max values, the 2 most common use case would be to filter between 2 numbers or dates, you can do that with the Slider & Date Range Filters. The range can also be defined as inclusive (`>= 0 and <= 10`) or exclusive (`> 0 and < 10`), the default is exclusive but you can change that, see below for more info.

### Using an Inclusive Range (default is Exclusive)
By default all the range filters are with exclusive range, which mean between value `x` and `y` but without including them. If you wish to include the `x` and `y` values, you can change that through the `operator` property.
Expand Down Expand Up @@ -123,20 +122,20 @@ You could also define certain options as a global level (for the entire grid or

```ts
this.gridOptions = {
defaultFilterOptions: {
defaultFilterOptions: {
// Note: that `date`, `select` and `slider` are combining both compound & range filters together
date: { minDate: 'today' },
date: { range: { min: 'today' } },
select: { minHeight: 350 }, // typed as MultipleSelectOption
slider: { sliderStartValue: 10 }
}
}
```

### Using a Date Range Filter
The date range filter allows you to search data between 2 dates (it uses [Flatpickr Range](https://flatpickr.js.org/examples/#range-calendar) feature).
The date range filter allows you to search data between 2 dates (it uses [Vanilla-Calendar Range](https://vanilla-calendar.pro/) feature).

##### Component
import { Filters, FlatpickrOption, Formatters, GridOption, OperatorType } from '@slickgrid-universal/common';
import { Filters, Formatters, GridOption, OperatorType, VanillaCalendarOption } from '@slickgrid-universal/common';

```typescript
export class GridBasicComponent {
Expand All @@ -148,14 +147,16 @@ export class GridBasicComponent {
// your columns definition
this.columnDefinitions = [
{
id: 'finish', name: 'Finish', field: 'finish', headerKey: 'FINISH', formatter: Formatters.dateIso, sortable: true, minWidth: 75, width: 120, exportWithFormatter: true,
id: 'finish', name: 'Finish', field: 'finish', headerKey: 'FINISH',
minWidth: 75, width: 120, exportWithFormatter: true,
formatter: Formatters.dateIso, sortable: true,
type: FieldType.date,
filterable: true,
filter: {
model: Filters.dateRange,

// override any of the Flatpickr options through "filterOptions"
editorOptions: { minDate: 'today' } as FlatpickrOption
// override any of the Vanilla-Calendar options through "filterOptions"
editorOptions: { range: { min: 'today' } } as VanillaCalendarOption
}
},
];
Expand All @@ -167,14 +168,14 @@ export class GridBasicComponent {
}
```

##### Filter Options (`FlatpickrOption` interface)
All the available options that can be provided as `filterOptions` to your column definitions can be found under this [FlatpickrOption interface](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/interfaces/flatpickrOption.interface.ts) and you should cast your `filterOptions` to that interface to make sure that you use only valid options of the [Flatpickr](https://flatpickr.js.org/) library.
#### Filter Options (`VanillaCalendarOption` interface)
All the available options that can be provided as `filterOptions` to your column definitions can be found under this [VanillaCalendarOption interface](https://github.com/ghiscoding/slickgrid-universal/blob/master/packages/common/src/interfaces/vanillaCalendarOption.interface.ts) and you should cast your `filterOptions` with the expected interface to make sure that you use only valid settings of the [Vanilla-Calendar](https://vanilla-calendar.pro/docs/reference/additionally/settings) library.

```ts
filter: {
model: Filters.dateRange,
model: Filters.compoundDate,
filterOptions: {
minDate: 'today'
} as FlatpickrOption
range: { min: 'today' }
} as VanillaCalendarOption
}
```
78 changes: 34 additions & 44 deletions docs/column-functionalities/filters/Styling-Filled-Filters.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
You can style any (or all) of the Filter(s) when they have value, the lib will automatically add a `filled` CSS class which you can style as your wish. There is no style by default, if you wish to add styling, you will be required to add your own.
You can style any (or all) of the Filter(s) when they have value, the lib will automatically add a `filled` CSS class which you can style as your wish. There is no style by default, if you wish to add styling, you will be required to add your own.

## Styled Example
## Styled Example
![grid_filled_styling](https://user-images.githubusercontent.com/643976/51334569-14306d00-1a4e-11e9-816c-439796eb8a59.png)

## Code example
For example, the print screen shown earlier was styled using this piece of SASS (`.scss`) code. Also note that the demo adds a Font-Awesome icon which can be used with `font-family: "FontAwesome"` and the relevent unicode character, for example the filter icon is `content: " \f0b0"`. You can basically add a lot of different styling to your populated filters.
For example, the print screen shown earlier was styled using this piece of SASS (`.scss`) code. You can customize the styling to your liking.

```scss
$filter-filled-bg-color: darkorange;

.search-filter.filled {
// color: rgb(189, 104, 1);
// font-weight: bold;
background-color: $filter-filled-bg-color;
.ms-choice {
// color: rgb(189, 104, 1);
// font-weight: bold;
background-color: $filter-filled-bg-color;
}


input, input.flatpickr-input {
// border: 1px solid darken(rgb(204, 204, 204), 15%) !important;
// color: rgb(189, 104, 1);
// font-weight: bold;
background-color: $filter-filled-bg-color !important;
$slick-filled-filter-color: $slick-form-control-focus-border-color;
$slick-filled-filter-border: $slick-form-control-border;
$slick-filled-filter-box-shadow: $slick-form-control-focus-border-color;
$slick-filled-filter-font-weight: 400;

.slick-headerrow {
input.search-filter.filled,
.search-filter.filled input,
.search-filter.filled .date-picker input,
.search-filter.filled .input-group-addon.slider-value,
.search-filter.filled .input-group-addon.slider-range-value,
.search-filter.filled .input-group-addon select {
color: $slick-filled-filter-color;
font-weight: $slick-filled-filter-font-weight;
border: $slick-filled-filter-border;
box-shadow: $slick-filled-filter-box-shadow;
&.input-group-prepend {
border-right: 0;
}
&.input-group-append {
border-left: 0;
}
}
/*
&.ms-parent, .flatpickr > input, .input-group > input {
border: 1px solid darken(rgb(204, 204, 204), 15%) !important;
}
*/

div.flatpickr:after, button > div:after, & + span:after, .input-group > span:after {
font-family: "FontAwesome";
font-size: 75%;
content: " \f0b0";
position: absolute;
top: 2px;
right: 5px;
z-index: 1000;
color: #ca880f;
}

.ms-choice > div:after {
top: -4px;
right: 16px;
.search-filter.filled .input-group-prepend select {
border-right: 0;
}
& + span:after {
top: 6px;
right: 10px;
.search-filter.filled .ms-choice {
box-shadow: $slick-filled-filter-box-shadow;
border:$slick-filled-filter-border;
span {
font-weight: $slick-filled-filter-font-weight;
color: $slick-filled-filter-color;
}
}
}
```
Loading

0 comments on commit fb6e950

Please sign in to comment.