Skip to content

Commit b58701a

Browse files
Merge branch 'master' into upgrade-to-v5
2 parents f3386a9 + 0385386 commit b58701a

File tree

91 files changed

+4304
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4304
-171
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Announcing Chapel 1.33!
3+
date: 2023-12-14T23:14:56.509Z
4+
externalLink: https://chapel-lang.org/blog/posts/announcing-chapel-1.33/
5+
author: Brad Chamberlain
6+
authorimage: https://chapel-lang.org/blog/authors/brad-chamberlain/photo.jpg
7+
disable: false
8+
tags:
9+
- opensource
10+
- HPC
11+
- chapel
12+
---
13+
External blog
Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: "Dark Mode Theming in Grommet: Adding dark and light theme modes"
3-
date: 2020-10-21T12:49:17.679Z
2+
title: "Dark Mode Theming in Grommet - Part 2: Adding dark and light theme modes"
3+
date: 2023-12-15T15:46:57.782Z
44
featuredBlog: false
55
priority: null
66
author: Matt Glissmann
77
authorimage: /img/blogs/Avatar1.svg
88
thumbnailimage: null
99
tags:
10-
- Grommet
10+
- grommet
1111
- theme
1212
- mode
1313
- opensource
@@ -16,46 +16,44 @@ tags:
1616

1717
In [Part 1](/blog/dark-mode-theming-in-grommet-how-to-set-up-and-apply-a-theme) of this 3-part series on Grommet’s support for light and dark modes, I covered setting up a simple Grommet app and applying a theme to that app. Here in Part 2, I’ll guide you through the steps required to implement dark/light theme modes. At the conclusion of this post, the app will have some basic UI components and a control to toggle the interface between light and dark modes.
1818

19-
- [Part 1 - How to set up and apply a Theme](/blog/dark-mode-theming-in-grommet-how-to-set-up-and-apply-a-theme)
20-
- Part 2 - Adding dark and light theme modes
21-
- Part 3 - Theme color customizations
19+
* [Part 1 - How to set up and apply a Theme](/blog/dark-mode-theming-in-grommet-how-to-set-up-and-apply-a-theme)
20+
* Part 2 - Adding dark and light theme modes
21+
* [Part 3 - Theme color customizations](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-theme-color-customization/)
2222

2323
In this post, I’ll cover content regarding adding a theme toggle button, including:
24-
24+
2525
* Introducing the `themeMode` prop, which allows specifying which version of the theme the app renders.
2626

2727
* Adding a button to the interface to serve as a control to toggle the value that gets passed to `themeMode`.
2828

2929
![f10thememodetoggle](https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/f10thememodetoggle-1603286872853.gif)
3030

3131
## Adding a Theme Toggle Button
32+
3233
For this exercise, you’ll continue modifying your app from the example you created in Part 1 of this series. If you are catching up and joining midstream, you can reference this [Codesandbox](https://codesandbox.io/s/grommet-theme-toggle-1adding-theme-rg91i?file=/src/App.js).
33-
34+
3435
First, I’m going to show you how to add a button that, when clicked, will toggle the theme between light and dark modes.
35-
36-
In App.js:
37-
38-
Add the [_**themeMode**_](https://v2.grommet.io/grommet#themeMode) prop to the `<Grommet>` component and set its value to `"dark"`. The value referenced by `themeMode` specifies whether Grommet should use the dark or light versions of the theme.
3936

37+
In App.js:
4038

39+
Add the ***[themeMode](https://v2.grommet.io/grommet#themeMode)*** prop to the `<Grommet>` component and set its value to `"dark"`. The value referenced by `themeMode` specifies whether Grommet should use the dark or light versions of the theme.
4140

4241
```javascript
43-
<Grommet full theme={theme} themeMode="dark">
42+
<Grommet full theme={grommet} themeMode="dark">
4443
```
4544

4645
This should result in:
4746

48-
4947
![f4part 2 toggle](https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/f4part-2-toggle-1603286827841.png)
5048

5149
Next, add a button to serve as the toggle control.
52-
50+
5351
Import `Button` as a component from Grommet
54-
5552

5653
```javascript
5754
import { Grommet, Anchor, Box, Button, List, Heading, Paragraph, Text } from "grommet";
5855
```
56+
5957
Below the `<List>`, add a theme toggle button with some formatting props and an `onClick` handler.
6058

6159
```javascript
@@ -67,23 +65,22 @@ Below the `<List>`, add a theme toggle button with some formatting props and an
6765
onClick={() => {}}
6866
/>
6967
```
68+
7069
## Enable Toggling of ThemeMode’s State
70+
7171
Next, make the theme mode dynamic by adding a variable `darkMode` to hold the current theme mode, storing it in the component’s state, and adjusting the state each time the theme toggle button is clicked.
72-
73-
Create variable `darkMode` and its state using React’s [`useState` Hook](https://reactjs.org/docs/hooks-state.html).
7472

73+
Create variable `darkMode` and its state using React’s [`useState` Hook](https://reactjs.org/docs/hooks-state.html).
7574

7675
```javascript
7776
const App = () => {
7877
const [darkMode, setDarkMode] = React.useState(false);
7978
return (
8079
<Grommet full theme={grommet} themeMode="dark">
81-
8280
```
8381
8482
Modify the button’s `onClick` handler to toggle `darkMode` between `true` and `false`.
8583
86-
8784
```html
8885
<Button
8986
label="Toggle Theme"
@@ -92,27 +89,25 @@ Modify the button’s `onClick` handler to toggle `darkMode` between `true` and
9289
margin="large"
9390
onClick={() => setDarkMode(!darkMode)}
9491
/>
95-
9692
```
9793
9894
Next, replace `themeMode`’s value to be “dark” when `darkMode` is true, and “light” when `darkMode` is false.
9995
100-
```javascript
101-
<Grommet full theme={theme} themeMode={darkMode ? "dark" : "light"} >
96+
```javascript
97+
<Grommet full theme={grommet} themeMode={darkMode ? "dark" : "light"} >
10298
```
10399
104100
The theme mode toggling should be good to go. Give the toggle button a few clicks!
105101
106102
![f2thememodetogglemid](https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/f2thememodetogglemid-1603286807584.gif)
107103
108104
## Incorporating More Visual Interest
105+
109106
Finally, to better demonstrate a changing theme, let’s add some more interesting visuals to the application.
110107
111108
Remove the following from App.js
112109
113-
114110
```javascript
115-
116111
<Paragraph>We will be modifying this project to:</Paragraph>
117112
<List data={projectTasks}>
118113
{(task, index) => (
@@ -125,16 +120,13 @@ Remove the following from App.js
125120
126121
Then, import the DemoSection from `DemoSection.js` and add it below the toggle button. DemoSection contains a sampling of Grommet components to better demonstrate the effect themeMode has across components.
127122
128-
129123
```javascript
130124
import { DemoSection } from "./DemoSection";
131125
```
132126
133127
Then add DemoSection directly beneath this button.
134128
135-
136129
```javascript
137-
138130
<Button
139131
label="Toggle Theme"
140132
primary
@@ -150,7 +142,7 @@ At this point, your code and resulting app should resemble what is shown in this
150142
![f14part 2 non animated white theme toggle](https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/f14part-2-non-animated-white-theme-toggle-1603286900031.png)
151143
152144
As quick review, here’s what we’ve done to modify the app:
153-
145+
154146
* Added `themeMode` as a prop on the `<Grommet>` component. The value provided to `themeMode` specifies which mode of the theme to use.
155147
156148
* Created a state variable called `darkMode` to store whether the theme should currently be in dark mode.
@@ -159,4 +151,4 @@ As quick review, here’s what we’ve done to modify the app:
159151
160152
* Added a `<Button>` to serve as control to toggle the theme mode by toggling the state of `darkMode`.
161153
162-
* Lastly, made the app interface a bit more interesting to demonstrate how various components are affected by toggling the `themeMode`.That’s it for Part 2! In Part 3, I’ll demonstrate how to customize a theme with custom dark and light mode colors. Don’t forget to check back at the HPE DEV blog to catch Part 3 of this series. Again, if you have any questions, please feel free to reach out to me and others in the Grommet group on our Slack channel.
154+
* Lastly, made the app interface a bit more interesting to demonstrate how various components are affected by toggling the `themeMode`. That’s it for Part 2! In [Part 3](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-theme-color-customization/), I’ll demonstrate how to customize a theme with custom dark and light mode colors. Don’t forget to check back at the HPE DEV blog to catch [Part 3](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-theme-color-customization/) of this series. Again, if you have any questions, please feel free to reach out to me and others in the Grommet group on our Slack channel.
Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,100 @@
11
---
2-
title: "Dark Mode Theming in Grommet: How to set up and apply a theme"
3-
date: 2020-10-14T07:50:10.733Z
4-
author: Matt Glissmann
5-
tags: ["grommet","opensource"]
6-
authorimage: "/img/blogs/Avatar6.svg"
7-
featuredBlog: false
8-
priority:
9-
thumbnailimage:
2+
title: "Dark Mode Theming in Grommet - Part 1: How to set up and apply a theme"
3+
date: 2023-12-15T15:45:24.933Z
4+
featuredBlog: true
5+
priority: 3
6+
author: Matt Glissmann
7+
authorimage: /img/blogs/Avatar6.svg
8+
thumbnailimage: null
9+
tags:
10+
- grommet
11+
- opensource
1012
---
1113
![darkmode intro part1](https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/darkmode-intro-part1-1603293464825.png)
1214

1315
This post is Part 1 of a three-part series.
1416

15-
- Part 1 - How to set up and apply a theme
16-
- Part 2 - Adding dark and light theme modes
17-
- Part 3 - Theme color customization
17+
* Part 1 - How to set up and apply a theme
18+
* [Part 2 - Adding dark and light theme modes](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-adding-dark-and-light-theme-modes/)
19+
* [Part 3 - Theme color customization](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-theme-color-customization/)
1820

1921
As a UI/UX developer at HPE, I use [Grommet](https://grommet.io) extensively. I am also a regular contributor on the [Grommet Slack](https://grommet.slack.com) channels where the Theming capabilities, especially Grommet’s support for light and dark modes, are a consistent topic of interest.
2022

2123
[Grommet](https://grommet.io) has robust support for light and dark themes. Due to the apparent interest in this topic, I thought I’d share my approach on how to get started with theme mode styling in [Grommet](https://grommet.io).
2224

2325
To illustrate the method I use, I’m going to create a simple application demonstrating the ability to toggle between light and dark modes. By the end of this 3-part blog series, I will have demonstrated how to:
2426

25-
- Apply a theme in a Grommet application
26-
- Incorporate dark and light theme modes
27-
- Modify a theme to apply custom colors in dark and light modes
27+
* Apply a theme in a Grommet application
28+
* Incorporate dark and light theme modes
29+
* Modify a theme to apply custom colors in dark and light modes
2830

2931
The final product will be a simple application with a custom theme applied and the ability for a user to toggle between the app’s light and dark modes.
3032

3133
<img src="https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/themetutorialapp-1602698870239.gif" style="height:300px, width:300px" />
3234

3335
# Setup for the tutorial
36+
3437
## Prerequisites
38+
3539
This tutorial assumes familiarity with HTML, JavaScript, and React. However, even if any of these are new to you, you should be able to follow along and complete the exercise.
3640

3741
## Get the Starter Code
42+
3843
Open this [starting code](https://codesandbox.io/s/grommet-theme-toggle-0starter-1k1cv?file=/src/App.js) in your browser. Create your own copy by clicking 'Fork' from the menu in the upper right corner. The starter app will look like this:
3944

4045
<img src="https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/picture-2-1602661773922.png" />
4146

4247
## Starter Code Orientation
48+
4349
### Development Environment
44-
For this tutorial, I’m using [Codesandbox](https://codesandbox.io/) as the development environment. [Codesandbox](https://codesandbox.io/) presents the user with:
4550

46-
- An interface for the project’s file and directory structure
47-
- A text editor for editing files
48-
- A browser window to view and interact with the application
51+
For this tutorial, I’m using [Codesandbox](https://codesandbox.io/) as the development environment. Codesandbox presents the user with:
52+
53+
* An interface for the project’s file and directory structure
54+
* A text editor for editing files
55+
* A browser window to view and interact with the application
4956

5057
### Project Structure and Dependencies
58+
5159
The project structure mimics a minimal Create React App (CRA) structure and is organized like so:
5260

53-
- /public
54-
- index.html (this gets loaded by the browser and is what renders src/index.js)
55-
- /src
56-
- index.js (This is the project’s root file. I won’t be modifying it.)
57-
- App.js
58-
- DemoSection.js (This is a component I will use later in the tutorial)
59-
- Package.json (Create React App ships with `react`, `react-dom`, and `react-scripts` as dependencies. Additionally, I’ve added `grommet` and its peer dependency, `styled-components`, to the starter project.)
61+
* /public
62+
63+
* index.html (this gets loaded by the browser and is what renders src/index.js)
64+
* /src
65+
66+
* index.js (This is the project’s root file. I won’t be modifying it.)
67+
* App.js
68+
* DemoSection.js (This is a component I will use later in the tutorial)
69+
* Package.json (Create React App ships with `react`, `react-dom`, and `react-scripts` as dependencies. Additionally, I’ve added `grommet` and its peer dependency, `styled-components`, to the starter project.)
6070

6171
### App.js
72+
6273
For this tutorial, most of the development will happen in App.js. The App.js file consists of three parts; imports, projectTasks array, and the App component.
6374

6475
Import of React and Grommet components:
6576

66-
6777
```javascript
6878
import React from "react";
6979
import { Grommet, Anchor, Box, List, Heading, Paragraph, Text } from "grommet";
7080
```
7181

7282
`projectTasks` array with the tasks to be implemented
7383

74-
7584
```javascript
7685
const projectTasks = [
7786
"Apply a Theme - Add an existing theme to provide some styling",
7887
`Add Theme Toggle Button - Add a button, which when clicked,
7988
will toggle the theme between light and dark modes`,
8089
"Customize Theme - Add custom colors to theme"
8190
];
82-
````
91+
```
8392

8493
The `App` is composed of the following Grommet components:
8594

86-
- `<Grommet>` is the top level Grommet container
87-
- `<Box>` for some basic page layout
88-
- For the page’s content, I have `<Heading>`,`< Paragraph>`, and `<List>` which iterates over the `projectTasks` array, returning a `<Text>` component for each task.
89-
95+
* `<Grommet>` is the top level Grommet container
96+
* `<Box>` for some basic page layout
97+
* For the page’s content, I have `<Heading>`,`< Paragraph>`, and `<List>` which iterates over the `projectTasks` array, returning a `<Text>` component for each task.
9098

9199
```javascript
92100
const App = () => {
@@ -115,36 +123,29 @@ export default App;
115123
```
116124

117125
# Applying a Theme
118-
To provide some initial styling, I’ll apply the `grommet` theme. In Part 3 of this series, I will show you how to customize and incorporate a custom theme.
126+
127+
To provide some initial styling, I’ll apply the `grommet` theme. In [Part 3](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-theme-color-customization/) of this series, I will show you how to customize and incorporate a custom theme.
119128

120129
In App.js, import and apply the Grommet theme:
121130

122131
Import grommet theme
123132

124-
125-
```javascript
133+
```javascript
126134
import { grommet } from "grommet"; 
127-
````
135+
```
128136

129137
Apply it by adding `theme={grommet}` to the Grommet component.
130138

131-
132139
```javascript
133140
<Grommet full theme={grommet}>
134141
```
135142

136-
137-
138-
139143
![matt1-picture 3](https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/picture-3-1602661789429.png)
140144

141-
142-
143145
![matt1-picture 4](https://hpe-developer-portal.s3.amazonaws.com/uploads/media/2020/9/picture-4-1602661802053.png)
144146

145147
Your code and resulting app should resemble this [Codesandbox](https://codesandbox.io/s/grommet-theme-toggle-1adding-theme-rg91i?file=/src/App.js), and the app’s UI should have updated with the applied theme.
146148

147149
At this point, you now have an understanding for how to apply a theme to a Grommet app. This is the foundation from which we will build custom theming. In my next post, I will show you how to add dark/light theming and give users control over toggling between theme modes. In my final post, I will wrap up with a how to customize a theme with custom dark and light mode colors.
148150

149-
Stay tuned to the [HPE DEV blog](/blog) to catch Parts 2 and 3 of this series. If you have any questions, please feel free to reach out to me and others in the Grommet group on our [Slack channel](https://app.slack.com/client/T04LMHMUT/C04LMHN59).
150-
151+
Stay tuned to the [HPE DEV blog](/blog) to catch Parts [2](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-adding-dark-and-light-theme-modes/) and [3](https://developer.hpe.com/blog/dark-mode-theming-in-grommet-theme-color-customization/) of this series. If you have any questions, please feel free to reach out to me and others in the Grommet group on our [Slack channel](https://app.slack.com/client/T04LMHMUT/C04LMHN59).

0 commit comments

Comments
 (0)