Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(datetime): add playground for styling wheel pickers #2982

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions docs/api/datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import HighlightedDatesCallback from '@site/static/usage/v7/datetime/highlighted

import MultipleDateSelection from '@site/static/usage/v7/datetime/multiple/index.md';

import Theming from '@site/static/usage/v7/datetime/theming/index.md';
import GlobalTheming from '@site/static/usage/v7/datetime/styling/global-theming/index.md';
import WheelStyling from '@site/static/usage/v7/datetime/styling/wheel-styling/index.md';

<head>
<title>ion-datetime: Ionic API Input for Datetime Format Picker</title>
Expand Down Expand Up @@ -310,13 +311,21 @@ A callback is better when the highlighted dates are recurring, such as birthdays

<HighlightedDatesCallback />

## Theming
## Styling

### Global Theming

Ionic's powerful theming system can be used to easily change your entire app to match a certain theme. In this example, we used the [Color Creator](../theming/colors#new-color-creator) and the [Stepped Color Generator](../theming/themes#stepped-color-generator) to create a rose color palette that we can use for `ion-datetime`.

The benefit of this approach is that every component, not just `ion-datetime`, can automatically take advantage of this theme.

<Theming />
<GlobalTheming />

### Wheel Pickers

The wheels used in `ion-datetime` can be styled through a combination of shadow parts and CSS variables. This applies to both the columns in wheel-style datetimes, and the month/year picker in grid-style datetimes.

<WheelStyling />

## Time Zones

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Datetime</title>
<link rel="stylesheet" href="../../../common.css" />
<script src="../../../common.js"></script>
<link rel="stylesheet" href="../../../../common.css" />
<script src="../../../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7/css/ionic.bundle.css" />
<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ import angular_global_css from './angular/global_css.md';
},
},
}}
src="usage/v7/datetime/theming/demo.html"
src="usage/v7/datetime/styling/global-theming/demo.html"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```css
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-fade-background-rgb: 245, 235, 247;
}

ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}

ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```html
<ion-datetime presentation="date" [preferWheel]="true"></ion-datetime>
```
39 changes: 39 additions & 0 deletions static/usage/v7/datetime/styling/wheel-styling/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Datetime</title>
<link rel="stylesheet" href="../../../../common.css" />
<script src="../../../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7/css/ionic.bundle.css" />

<style>
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-fade-background-rgb: 245, 235, 247;
}

ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}

ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
Comment on lines +24 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not related to this PR, but this style doesn't seem to be impacting the active wheel item in the angular stackblitz (with 7.0.7-dev.11685554390.10c2ca9b). Is that a known issue? It's working with the other frameworks.

Copy link
Contributor Author

@averyjohnston averyjohnston Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the Angular Stackblitzes are weird. There's a known Stackblitz bug we've been trying to resolve with them for a while where the Angular setup doesn't actually install the version you specify. AFAIK you have to download the repo (or just copy-paste the code) and install the dev build locally instead.

</style>
</head>

<body>
<ion-app>
<ion-content>
<div class="container">
<ion-datetime presentation="date" prefer-wheel="true"></ion-datetime>
</div>
</ion-content>
</ion-app>
</body>
</html>
33 changes: 33 additions & 0 deletions static/usage/v7/datetime/styling/wheel-styling/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Playground from '@site/src/components/global/Playground';

import javascript from './javascript.md';

import react_main_tsx from './react/main_tsx.md';
import react_main_css from './react/main_css.md';

import vue from './vue.md';

import angular_example_component_html from './angular/example_component_html.md';
import angular_example_component_css from './angular/example_component_css.md';

<Playground
version="7"
code={{
javascript,
react: {
files: {
'src/main.tsx': react_main_tsx,
'src/main.css': react_main_css,
},
},
vue,
angular: {
files: {
'src/app/example.component.html': angular_example_component_html,
'src/app/example.component.css': angular_example_component_css,
},
},
}}
src="usage/v7/datetime/styling/wheel-styling/demo.html"
size="250px"
/>
20 changes: 20 additions & 0 deletions static/usage/v7/datetime/styling/wheel-styling/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```html
<style>
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-fade-background-rgb: 245, 235, 247;
}

ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}

ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
</style>

<ion-datetime presentation="date" prefer-wheel="true"></ion-datetime>
```
16 changes: 16 additions & 0 deletions static/usage/v7/datetime/styling/wheel-styling/react/main_css.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```css
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-fade-background-rgb: 245, 235, 247;
}

ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}

ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
```
11 changes: 11 additions & 0 deletions static/usage/v7/datetime/styling/wheel-styling/react/main_tsx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```tsx
import React from 'react';
import { IonDatetime } from '@ionic/react';

import './main.css';

function Example() {
return <IonDatetime presentation="date" preferWheel={true}></IonDatetime>;
}
export default Example;
```
31 changes: 31 additions & 0 deletions static/usage/v7/datetime/styling/wheel-styling/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
```html
<template>
<ion-datetime presentation="date" :prefer-wheel="true"></ion-datetime>
</template>

<script lang="ts">
import { IonDatetime } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
components: { IonDatetime },
});
</script>

<style scoped>
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-fade-background-rgb: 245, 235, 247;
}

ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}

ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
</style>
```