Skip to content

Commit 322e49e

Browse files
authored
📚 DOCS: Add page on CSS classes (#7)
1 parent 14550d5 commit 322e49e

Some content is hidden

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

42 files changed

+478
-101
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This package is an iteration on sphinx-panels and intends to replace it.
5050
- `tabbed` -> `tab-item`
5151
- include `:sync:` option to synchronize tab selection across sets
5252
- Minimises direct use of CSS classes (encourage to not use them)
53-
- More declarative, easy to understand options
53+
- More declarative, easy to understand options, easier to validate
5454
- Easier to work with non-HTML outputs
5555
- Easier to improve/refactor
5656
- Updated Bootstrap CSS v4 -> v5
@@ -65,9 +65,6 @@ This package is an iteration on sphinx-panels and intends to replace it.
6565
- card header/footer syntax? (don't really want to have to use separate directives for these, hence `^^^`/`+++` syntax)
6666
- auto-wrap `grid-item` and `tab-item`, if not already inside `grid` or `tab-set`?
6767

68-
note that directly using classes should be used as a "last resort",
69-
and to please open an issue if you find you are commonly using a certain class.
70-
7168
grids items cannot contain headers; is this in anyway possible with docutils structure?
7269

7370
naming of directives/roles: standard prefix?
@@ -82,8 +79,6 @@ horizontal card (grid row inside card, picture on left)
8279

8380
horizontally scrollable cards: (see <https://stackoverflow.com/questions/35993300/horizontally-scrollable-list-of-cards-in-bootstrap>)
8481

85-
div directive
86-
8782
subtitle for card (see <https://material.io/components/cards#anatomy>)
8883

8984
paragraph and tab-set in grid-item

docs/additional.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ These are additional components that are not part of the standard Materials Desi
77
## `article-info`
88

99
This directive is used to display a block of information about an article,
10-
normally positioned just below the title of the article (show below with non-standard outline).
10+
normally positioned just below the title of the article (shown below with non-standard outline).
1111

1212
```{article-info}
1313
:avatar: images/ebp-logo.png
@@ -45,7 +45,7 @@ so you can use substitutions like:
4545
### options
4646

4747
avatar
48-
: A URI (relative file path or URL) to an image for use as the avatar.
48+
: A URI (relative file path or URL) to an image for use as the avatar (a user portrait, logo or branded graphic).
4949

5050
avatar-alt
5151
: Alternative text for the avatar.

docs/cards.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ link
175175
link-type
176176
: Type of link: `url` (default), `ref`, `doc`, `any`.
177177

178-
no-shadow
179-
: Do not draw a shadow around the card.
178+
shadow
179+
: The size of the shadow below the card: `none`, `sm` (default), `md`, `lg`.
180180

181181
class-card
182182
: Additional CSS classes for the card container element.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
]
1717

1818
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
19-
myst_enable_extensions = ["colon_fence", "deflist", "substitution"]
19+
myst_enable_extensions = ["colon_fence", "deflist", "substitution", "html_image"]
2020

2121
myst_substitutions = {
2222
"loremipsum": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "

docs/css_classes.md

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
# CSS Classes
2+
3+
For most roles/directive, it is preferentially recommended to use the available options to style components since, for example, this allows for better cross-output-format styling.
4+
5+
But for custom cases, these roles/directives also provide `class` options for adding CSS classes directly to element, or you can directly use the `div` directive.
6+
All CSS classes that are part of sphinx-design are prefixed with `sd-`.
7+
8+
:::{div} sd-text-center sd-font-italic sd-text-primary
9+
Some CSS styled text
10+
:::
11+
12+
`````{dropdown} Syntax
13+
:icon: code
14+
:color: light
15+
16+
````{tab-set-code}
17+
```{literalinclude} ./snippets/myst/div-basic.txt
18+
:language: markdown
19+
```
20+
```{literalinclude} ./snippets/rst/div-basic.txt
21+
:language: rst
22+
```
23+
````
24+
`````
25+
26+
If you find yourself using a class(es) often, consider openeing an issue to request a new role/directive or option!
27+
28+
## Text
29+
30+
Classes are available for styling and alignment:
31+
32+
- Alignment:
33+
- `sd-text-justify`
34+
- `sd-text-left`
35+
- `sd-text-right`
36+
- `sd-text-center`
37+
- Weight:
38+
- `sd-font-weight-light`
39+
- `sd-font-weight-lighter`
40+
- `sd-font-weight-normal`
41+
- `sd-font-weight-bold`
42+
- `sd-font-weight-bolder`
43+
- Style
44+
- `sd-font-italic`
45+
- `sd-text-decoration-none`
46+
- `sd-text-lowercase`
47+
- `sd-text-uppercase`
48+
- `sd-text-capitalize`
49+
- Wrapping
50+
- `sd-text-wrap`
51+
- `sd-text-nowrap`
52+
- `sd-text-truncate` (requires `display: inline-block` or `display: block`)
53+
- Color
54+
- `sd-text-{semantic color name}` (uses `--sd-color-{semantic color name}` CSS variable)
55+
- `sd-bg-text-{semantic color name}` (uses `--sd-color-{semantic color name}-text` CSS variable)
56+
57+
## Display
58+
59+
Define the layout of an element and its children (see [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/display)):
60+
61+
- `sd-d-none`
62+
- `sd-d-inline`
63+
- `sd-d-inline-block`
64+
- `sd-d-block`
65+
- `sd-d-grid`
66+
- `sd-d-flex`
67+
- `sd-d-inline-flex`
68+
69+
Variants are also available for screen-sizes (xs, sm, md, lg), e.g. `sd-d-sm-none`.
70+
71+
Items within a flex box can also be aligned:
72+
73+
- `sd-align-items-start`
74+
- `sd-align-items-end`
75+
- `sd-align-items-center`
76+
77+
## Sizing
78+
79+
Size objects width/height by percentage:
80+
81+
- `sd-width-25`, `sd-height-25`
82+
- `sd-width-50`, `sd-height-50`
83+
- `sd-width-75`, `sd-height-75`
84+
- `sd-width-100`, `sd-height-100`
85+
- `sd-width-auto`, `sd-height-auto`
86+
87+
## Spacing
88+
89+
Padding (`p`) and margins (`m`) can be controlled with these classes for; (`t`)op, (`r`)ight, (`b`)ottom, (`l`)eft, `x` (left and right), and `y` (top and bottom).
90+
91+
Spacing are defined on a scale of 0 to 5, for example `sd-px-1` or `sd-mt-5`.
92+
93+
Note, for grids the special gutter classes `sd-g-{screen-size}-{spacing}` are used to set margins, or for only `x`/`y`; `sd-gx-{screen-size}-{spacing}`.
94+
95+
## Colors
96+
97+
Colors can be set using [CSS variable](./css_variables.md), they are defined for the semantic color names: primary, secondary, success, warning, danger, info, light, dark, and muted.
98+
99+
- `sd-bg-{name}`
100+
- `sd-bg-text-{name}`
101+
- `sd-text-{name}`
102+
- `sd-outline-{name}`
103+
104+
Additional transparent colouring:
105+
106+
- `sd-bg-transparent`
107+
- `sd-outline-transparent`
108+
- `sd-text-transparent`
109+
110+
## Borders
111+
112+
Borders can be applied to elements of thickness 0 to 5, for all are a specific side:
113+
114+
- `sd-border-{thickness}`
115+
- `sd-border-top-{thickness}`
116+
- `sd-border-bottom-{thickness}`
117+
- `sd-border-right-{thickness}`
118+
- `sd-border-left-{thickness}`
119+
120+
````{grid} 1 2 3 3
121+
:gutter: 1
122+
123+
```{grid-item-card}
124+
:shadow: none
125+
:class-card: sd-border-0
126+
127+
`sd-border-0`
128+
```
129+
```{grid-item-card}
130+
:shadow: none
131+
:class-card: sd-border-1
132+
133+
`sd-border-1`
134+
```
135+
```{grid-item-card}
136+
:shadow: none
137+
:class-card: sd-border-2
138+
139+
`sd-border-2`
140+
```
141+
```{grid-item-card}
142+
:shadow: none
143+
:class-card: sd-border-3
144+
145+
`sd-border-3`
146+
```
147+
```{grid-item-card}
148+
:shadow: none
149+
:class-card: sd-border-4
150+
151+
`sd-border-4`
152+
```
153+
```{grid-item-card}
154+
:shadow: none
155+
:class-card: sd-border-5
156+
157+
`sd-border-5`
158+
```
159+
````
160+
161+
Border can be rounded by different amounts using:
162+
163+
- `sd-rounded-0`
164+
- `sd-rounded-1`
165+
- `sd-rounded-2`
166+
- `sd-rounded-3`
167+
- `sd-rounded-pill`
168+
- `sd-rounded-circle`
169+
170+
````{grid} 1 2 3 3
171+
:gutter: 1
172+
173+
```{grid-item-card}
174+
:shadow: none
175+
:class-card: sd-rounded-0
176+
177+
`sd-rounded-0`
178+
```
179+
```{grid-item-card}
180+
:shadow: none
181+
:class-card: sd-rounded-1
182+
183+
`sd-rounded-1`
184+
```
185+
```{grid-item-card}
186+
:shadow: none
187+
:class-card: sd-rounded-2
188+
189+
`sd-rounded-2`
190+
```
191+
```{grid-item-card}
192+
:shadow: none
193+
:class-card: sd-rounded-3
194+
195+
`sd-rounded-3`
196+
```
197+
```{grid-item-card}
198+
:shadow: none
199+
:class-card: sd-rounded-pill
200+
201+
`sd-rounded-pill`
202+
```
203+
```{grid-item-card}
204+
:shadow: none
205+
:class-card: sd-rounded-circle
206+
207+
`sd-rounded-circle`
208+
```
209+
````
210+
211+
## Shadows
212+
213+
Shadows can be applied to box elements (the color of the shadow is defined using `--sd-color-shadow` CSS variable):
214+
215+
- `sd-shadow-none`
216+
- `sd-shadow-sm`
217+
- `sd-shadow-md`
218+
- `sd-shadow-lg`
219+
220+
````{grid} 1 2 3 4
221+
:gutter: 3
222+
223+
```{grid-item-card}
224+
:shadow: none
225+
226+
`sd-shadow-none`
227+
```
228+
```{grid-item-card}
229+
:shadow: sm
230+
231+
`sd-shadow-sm`
232+
```
233+
```{grid-item-card}
234+
:shadow: md
235+
236+
`sd-shadow-md`
237+
```
238+
```{grid-item-card}
239+
:shadow: lg
240+
241+
`sd-shadow-lg`
242+
```
243+
````
244+
245+
## Avatars
246+
247+
Avatars can represent a user or a brand,with a logo or branded graphic ([see Material Design imagery](https://material.io/design/communication/imagery.html#informational-imagery)).
248+
249+
These classes center an image, set their size and add a circular crop:
250+
251+
- `sd-avatar-xs`
252+
- `sd-avatar-sm`
253+
- `sd-avatar-md`
254+
- `sd-avatar-lg`
255+
- `sd-avatar-xl`
256+
257+
````{grid} 1 2 3 3
258+
:gutter: 1
259+
260+
```{grid-item-card} sd-avatar-xs
261+
<img src="images/ebp-logo.png" class="sd-avatar-xs sd-border-1">
262+
```
263+
```{grid-item-card} sd-avatar-sm
264+
<img src="images/ebp-logo.png" class="sd-avatar-sm sd-border-1">
265+
```
266+
```{grid-item-card} sd-avatar-md
267+
<img src="images/ebp-logo.png" class="sd-avatar-md sd-border-1">
268+
```
269+
```{grid-item-card} sd-avatar-lg
270+
<img src="images/ebp-logo.png" class="sd-avatar-lg sd-border-1">
271+
```
272+
```{grid-item-card} sd-avatar-xl
273+
<img src="images/ebp-logo.png" class="sd-avatar-xl sd-border-1">
274+
```
275+
````

docs/css.md renamed to docs/css_variables.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ html_static_path = ['_static']
88
html_css_files = ['custom.css']
99
```
1010

11+
For colors, there are nine semantic colors that can be defined.
12+
For each of these colors you should define:
13+
14+
- `--sd-color-{name}` as the actual color
15+
- `--sd-color-{name}-highlight` as the color used when the component is highlighted
16+
(e.g. if hovering over a button). By default, this is a 15% darker version of the original color.
17+
- `--sd-color-{name}-text` as the color to use for text displayed on top of the color.
18+
By default, this is dark grey for light colors and white for dark colors.
19+
1120
The defaults are:
1221

1322
```css

docs/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ additional
3838
:caption: Styling
3939
:hidden:
4040
41-
css
41+
css_variables
42+
css_classes
4243
```
4344

4445
```{toctree}
@@ -92,7 +93,7 @@ Roles and directives for {bdg-primary}`badges` and other components.
9293
:::
9394

9495
:::{grid-item-card} {octicon-16}`image` CSS Styling
95-
:link: css
96+
:link: css_variables
9697
:link-type: doc
9798

9899
Change the default colors and other CSS.

docs/snippets/myst/div-basic.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:::{div} sd-text-center sd-font-italic sd-text-primary
2+
Some CSS styled text
3+
:::

docs/snippets/rst/div-basic.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. div:: sd-text-center sd-font-italic sd-text-primary
2+
3+
Some CSS styled text

sphinx_design/badges_buttons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def run(self) -> List[nodes.Node]:
165165
if "click-parent" in self.options:
166166
classes.append("sd-stretched-link")
167167
if "shadow" in self.options:
168-
classes.append("sd-shadow")
168+
classes.append("sd-shadow-sm")
169169
if "class" in self.options:
170170
classes.extend(self.options["class"])
171171
node = self.create_ref_node(rawtext, target, bool(self.content), classes)

0 commit comments

Comments
 (0)