Skip to content

Commit

Permalink
feat(calendar): custom cell content (#930)
Browse files Browse the repository at this point in the history
* feat(calendar): custom cell content and style

* feat(calendar): add demo for custom cell content and style

* test(calendar): update unit test and snapshot for custom cell

* feat(calendar): add position to slotted content

* docs(calendar): add doc for custom cell

* fix(calendar): add return to getCellParent

* fix(calendar): add position part selection in elemental-theme

* docs(calendar): change wording

* refactor(calendar): change function and variable name

* test(calendar): remove unnecessary test case

* Update documents/src/pages/elements/calendar.md

* Update packages/halo-theme/src/custom-elements/ef-calendar.less

Co-authored-by: Nantawat Poothong <[email protected]>

---------

Co-authored-by: Nantawat Poothong <[email protected]>
  • Loading branch information
bualoy-napat and Nantawat-Poothong authored Sep 6, 2023
1 parent 298203c commit 781b9a8
Show file tree
Hide file tree
Showing 13 changed files with 7,347 additions and 2,398 deletions.
33 changes: 33 additions & 0 deletions documents/src/pages/elements/calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,39 @@ ef-calendar {
<ef-calendar first-day-of-week="3" value="2019-05-21"></ef-calendar>
```

## Customizing content of the cell

The calendar allows you to customize the content and style of a cell on particular date. You can set a `slot` attribute with value in format `yyyy-MM-dd`, `yyyy-MM` and `yyyy` as a key to indicate the specific day, month, year of the cell that need to be replaced with custom content.

::
```javascript
::calendar::
```
```html
<ef-calendar fill-cells range view="2020-05" min="2020-05-08">
<div class="custom-cell" slot="2020-05-02">
<ef-icon icon="emote"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-03">
<ef-icon icon="favorites"></ef-icon>
</div>
</ef-calendar>
```
```css
.custom-cell {
background-color: #1fa90a;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.custom-cell:hover {
background-color: #00c389;
}
```
::

## Adding footer content

The calendar supports adding footer content. This can be used to give information about the date entry, or to provide additional controls like 'reset'.
Expand Down
4 changes: 4 additions & 0 deletions packages/elemental-theme/src/custom-elements/ef-calendar.less
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
right: 1px;
left: 1px;
border-radius: @border-radius;

::slotted(*) {
position: absolute;
}
}

[part='footer'] {
Expand Down
56 changes: 56 additions & 0 deletions packages/elements/src/calendar/__demo__/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,62 @@
</script>
</demo-block>

<demo-block header="Slotted Cell Content">
<style>
.custom-cell {
background-color: #1fa90a;
border: 1px solid #fb8a03;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.custom-cell:hover {
background-color: #00c389;
border: 1px solid #00c389;
}
</style>
<ef-calendar fill-cells range view="2020-05" min="2020-05-08">
<div class="custom-cell" slot="2020-05-02">
<ef-icon icon="emote"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-03">
<ef-icon icon="favorites"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-09">
<ef-icon icon="emote"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-10">
<ef-icon icon="favorites"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-16">
<ef-icon icon="emote"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-17">
<ef-icon icon="favorites"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-23">
<ef-icon icon="emote"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-24">
<ef-icon icon="favorites"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-30">
<ef-icon icon="emote"></ef-icon>
</div>
<div class="custom-cell" slot="2020-05-31">
<ef-icon icon="favorites"></ef-icon>
</div>
<div class="custom-cell" slot="2020-06-06">
<ef-icon icon="emote"></ef-icon>
</div>
<div class="custom-cell" slot="2020-06-07">
<ef-icon icon="favorites"></ef-icon>
</div>
</ef-calendar>
</demo-block>

<demo-block header="Slotted Footer Content">
<ef-calendar>
<div
Expand Down
Loading

0 comments on commit 781b9a8

Please sign in to comment.