Skip to content

Commit

Permalink
docs(style): theming and foundation styles
Browse files Browse the repository at this point in the history
  • Loading branch information
clukhei committed Oct 25, 2024
1 parent a585d3b commit 2e5485c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 19 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/sync-to-gist.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sync to Gist
name: Sync to Lu Khei's Gist
on:
push:
branches:
Expand All @@ -15,4 +15,15 @@ jobs:
with:
gist_token: ${{ secrets.GIST_TOKEN }}
gist_id: 425e29332ec837d9ea4bbe90ff8d4a37
source_path: src/themes
source_path: src/themes
CSS-Gist:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Gist Repo Sync
uses: pentatonicfunk/action-gist-repo-sync@v1.8
with:
gist_token: ${{ secrets.GIST_TOKEN }}
gist_id: a31bfc0ea0c2b87d950b125f92835a76
source_path: src/css
1 change: 1 addition & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const parameters = {
["Introduction", "Installation", "Imports"],
"Usage",
"Frameworks",
"Style",
"Troubleshooting",
"Components",
"Patterns",
Expand Down
73 changes: 73 additions & 0 deletions docs/FoundationalStyles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Foundation

The library also provides styles for SGDS foundation to help users style your application wholistically with SGDS.
The styles help to override the default browser's native styles with SGDS.

These files are distributed as CSS files and are optional to import. These styles do not affect the web components and are not required in the web component.
However, do note that the CSS styles the light dom and may causes clash of styles if there are other styling libraries (for example, tailwind, bootstrap, sgds v1 and v2 css, etc.) used in your app.

Foundation aspects of SGDS includes:
- typography,
- body `<body>`
- paragraphs `<p>`
- labels `<label>`
- anchor `<a>`
- captions `<caption>`
- headers `<h1>, <h2>, <h3>, <h4>, <h5>, <h6>`
- list `<ol>, <ul>, <li>`
- grid system <sgds-badge show>work in progress</sgds-badge>

## Import

The CSS styles are dependent on the css variable tokens. Import the `themes/day.css` file first before importing the css files. If you required night mode, import `themes/night.css` as well.
The colors assigned to elements and class selectors will switch depending on day or night mode.

<strong>JS imports</strong>

```js
import "@govtechsg/sgds-web-component/themes/day.css"
//optional: if you are doing night mode
import "@govtechsg/sgds-web-component/themes/night.css"
import "@govtechsg/sgds-web-component/css/sgds.css"

```

<strong>CSS imports</strong>

```css
@import "@govtechsg/sgds-web-component/themes/day.css";
/** optional: if you are doing night mode */
@import "@govtechsg/sgds-web-component/themes/night.css";
@import "@govtechsg/sgds-web-component/css/sgds.css";
```

### Cherry pick the styles

`css/sgds.css` contains all the stylings found in the folder `css`. You can also choose to cherry pick the styles you required. For example, `label.css`

<strong>JS imports</strong>

```js
import "@govtechsg/sgds-web-component/themes/day.css"
//optional: if you are doing night mode
import "@govtechsg/sgds-web-component/themes/night.css"
import "@govtechsg/sgds-web-component/css/label.css"

```

<strong>CSS imports</strong>

```css
@import "@govtechsg/sgds-web-component/themes/day.css";
/** optional: if you are doing night mode */
@import "@govtechsg/sgds-web-component/themes/night.css";
@import "@govtechsg/sgds-web-component/css/label.css";
```

## Source files

<iframe
src='https://gist.github.com/clukhei/a31bfc0ea0c2b87d950b125f92835a76.pibb'
style="width: 100%; height: 1000px; border: 0;"
>
</iframe>
45 changes: 34 additions & 11 deletions docs/Stylings.md → docs/Theming.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Stylings
# Stylings

## Global Styles and Theming

Customize the styles at the `:root` level by overriding the values of css tokens defined in file
`@govtechsg/sgds-web-component/themes/day.css` file. This file contains the primitive and semantic css tokens. For system level UI changes, we encourage you to make primitive and semantic level style changes at the `:root` rather than component specific changes.

See all tokens in [github](https://github.com/GovTechSG/sgds-web-component/blob/restructure-v2/src/themes/day.css)

```css
// yourCustomCss.css
:root {
Expand All @@ -21,13 +19,41 @@ import "@govtechsg/sgds-web-component/themes/day.css";
import "./yourCustomCss.css"
```

## Component specific styles
### root.css

Primitives and semantic values are defined here. These tokens can also be found in `@govtechsg/sgds-web-component/themes` folder.

<iframe
src='https://gist.github.com/clukhei/425e29332ec837d9ea4bbe90ff8d4a37.pibb?file=root.css'
style="width: 100%; height: 300px; border: 0;"
>
</iframe>
### day.css

<iframe
src='https://gist.github.com/clukhei/425e29332ec837d9ea4bbe90ff8d4a37.pibb?file=day.css'
style="width: 100%; height: 300px; border: 0;"
>
</iframe>
### night.css

The styles of components are built in and can be modified via cssparts or css custom properties whenever we specify for such styling modificiations. This information will be specified under API section for each component
<iframe
src='https://gist.github.com/clukhei/425e29332ec837d9ea4bbe90ff8d4a37.pibb?file=night.css'
style="width: 100%; height: 300px; border: 0;"
>
</iframe>


## Component specific styles <sgds-badge show>work in progress</sgds-badge>

<!-- The styles of components are built in and can be modified via cssparts or css custom properties whenever we specify for such styling modificiations. This information will be specified under API section for each component
You will require some knowledge of web components and css to do so and the information can be readily available online like mdn web docs for [web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) and [css](https://developer.mozilla.org/en-US/docs/Web/CSS)
### css custom variable
### css custom variable <sgds-badge show>work in progress</sgds-badge>
Some components have defined css custom variable for styling of selected aspects of the element in the shadow DOM. See the API table for the available css custom variables
Expand All @@ -37,7 +63,7 @@ sgds-sidenav {
}
```
### cssparts
### cssparts <sgds-badge show>work in progress</sgds-badge>
Some components expose cssparts on selected elements of the shadow DOM. See the API table for each component on the css parts exposed.
Expand All @@ -47,9 +73,6 @@ sgds-footer::part(footer-bottom) {
font-family: "Times New Roman", Times, serif;
border: 10px dotted red;
}
```

``` -->

## External stylings

Any external stylings done on our web components like positioning needs to be done on your end. You can use [SGDS v2 library](https://designsystem.tech.gov.sg/get-started/)to leverage on the position stylings we provide e.g. ms-auto, flexbox, grids
6 changes: 6 additions & 0 deletions stories/getting-started/Style/FoundationStyle.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Meta, Markdown } from "@storybook/blocks";
import FoundationalStyles from '../../../docs/FoundationalStyles.md?raw';

<Meta title="Style/Foundation" />

<Markdown>{FoundationalStyles}</Markdown>
6 changes: 6 additions & 0 deletions stories/getting-started/Style/Theming.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Meta, Markdown } from "@storybook/blocks";
import Theming from '../../../docs/Theming.md?raw';

<Meta title="Style/Theming" />

<Markdown>{Theming}</Markdown>
6 changes: 0 additions & 6 deletions stories/getting-started/Usage/Stylings.mdx

This file was deleted.

0 comments on commit 2e5485c

Please sign in to comment.