Skip to content

Commit cca2cfb

Browse files
authored
✨ NEW: grid-item child-direction and child-align options (#15)
Control the direction and alignment of child items within the grid item.
1 parent 3050b4c commit cca2cfb

23 files changed

+159
-89
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ horizontal card (grid row inside card, picture on left)
7272

7373
subtitle for card (see <https://material.io/components/cards#anatomy>)
7474

75-
paragraph and tab-set in grid-item
76-
7775
rtd PRs not working
7876

7977
octicon in button text shown as raw HTML

docs/css_classes.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Some CSS styled text
2525

2626
If you find yourself using a class(es) often, consider opening an issue to request a new role/directive or option!
2727

28+
The `div` directive also has the `style` option, which allows you to add inline CSS styles, although it is not recommended to use this option for most cases.
29+
2830
## Text
2931

3032
Classes are available for styling and alignment:
@@ -70,16 +72,24 @@ Define the layout of an element and its children (see [`display`](https://develo
7072
- `sd-d-inline-block`
7173
- `sd-d-block`
7274
- `sd-d-grid`
73-
- `sd-d-flex`
75+
- `sd-d-flex-row` (align items horizontally)
76+
- `sd-d-flex-column` (align items vertically)
7477
- `sd-d-inline-flex`
7578

7679
Variants are also available for screen-sizes (xs, sm, md, lg), e.g. `sd-d-sm-none`.
7780

78-
Items within a flex box can also be aligned:
81+
Items within a flex box can also be aligned along the major axis or minor axis, dependant on the flex-direction.
82+
For example, using `sd-d-flex-column` and `sd-align-major-center` will center the items in the vertical direction.
83+
84+
- `sd-align-major-start`
85+
- `sd-align-major-end`
86+
- `sd-align-major-center`
87+
- `sd-align-major-spaced` (spaced to fill the full axis)
88+
- `sd-align-major-justify` (spaced to fill the full axis, with the first/last item on the edges of the axis)
7989

80-
- `sd-align-items-start`
81-
- `sd-align-items-end`
82-
- `sd-align-items-center`
90+
- `sd-align-minor-start`
91+
- `sd-align-minor-end`
92+
- `sd-align-minor-center`
8393

8494
## Sizing
8595

docs/grids.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ padding
284284
: Inner padding of grid.
285285
One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5.
286286

287-
text-align
288-
: Default horizontal text alignment: left, right, center or justify
289-
290287
outline
291288
: Create a border around the grid.
292289

@@ -313,12 +310,15 @@ padding
313310
: Inner padding of grid item.
314311
One (all) or four (top bottom left right) values from: 0, 1, 2, 3, 4, 5.
315312

313+
child-direction
314+
: Direction of children in the grid item: `column` (default) or `row`.
315+
316+
child-align
317+
: Alignment of children, along the `child-direction`: `start` (default), `end`, `center`, `justify` or `spaced`.
318+
316319
outline
317320
: Create a border around the grid item.
318321

319-
text-align
320-
: Default horizontal text alignment: left, right, center or justify
321-
322322
class
323323
: Additional CSS classes for the grid item element.
324324

docs/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sd_hide_title: true
77
::::{grid}
88
:reverse:
99
:gutter: 2 1 1 1
10-
:margin: 4 1 1 1
10+
:margin: 4 4 1 1
1111

1212
:::{grid-item}
1313
:columns: 12 4 4 4
@@ -20,20 +20,21 @@ sd_hide_title: true
2020

2121
:::{grid-item}
2222
:columns: 12 8 8 8
23-
:class: sd-align-items-center sd-fs-3
23+
:child-align: justify
24+
:class: sd-fs-3
2425

2526
A sphinx extension for designing beautiful, screen-size responsive web-components.
26-
:::
27-
::::
2827

2928
```{button-ref} get_started
3029
:color: primary
31-
:align: center
3230
:class: sd-fs-5
3331
3432
Get Started
3533
```
3634

35+
:::
36+
::::
37+
3738
Conflict free CSS
3839
: All CSS classes are prefixed, to avoid conflicts with other frameworks.
3940

docs/tabs.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ See the [Material Design](https://material.io/components/tabs) description for f
3636
## Synchronised Tabs
3737

3838
Use the `sync` option to synchronise the selected tab items across multiple tab-sets.
39+
Note, synchronisation requires that JavaScript is enabled.
3940

4041
::::{tab-set}
4142

@@ -121,10 +122,14 @@ Paragraph
121122
::::{tab-set}
122123

123124
:::{tab-item} Label1
125+
:sync: label-1
126+
124127
Content 1
125128
:::
126129

127130
:::{tab-item} Label2
131+
:sync: label-2
132+
128133
Content 2
129134
:::
130135

@@ -134,14 +139,21 @@ Content 2
134139
::::::{grid} 1 1 2 2
135140

136141
:::::{grid-item}
142+
:outline:
143+
144+
Initial paragraph
137145

138146
::::{tab-set}
139147

140148
:::{tab-item} Label1
149+
:sync: label-1
150+
141151
Content 1
142152
:::
143153

144154
:::{tab-item} Label2
155+
:sync: label-2
156+
145157
Content 2
146158
:::
147159

@@ -150,19 +162,26 @@ Content 2
150162
:::::
151163

152164
:::::{grid-item}
165+
:outline:
153166

154167
::::{tab-set}
155168

156169
:::{tab-item} Label1
170+
:sync: label-1
171+
157172
Content 1
158173
:::
159174

160175
:::{tab-item} Label2
176+
:sync: label-2
177+
161178
Content 2
162179
:::
163180

164181
::::
165182

183+
Ending paragraph
184+
166185
:::::
167186

168187
::::::

sphinx_design/article_info.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def run(self) -> List[nodes.Node]:
7777
# TODO only in html (hide in latex)
7878
avatar_column = create_component(
7979
"grid-item",
80-
["sd-col", "sd-col-auto", "sd-d-flex", "sd-align-items-center"],
80+
["sd-col", "sd-col-auto", "sd-d-flex-row", "sd-align-minor-center"],
8181
)
8282
self.set_source_info(avatar_column)
8383
avatar_classes = ["sd-avatar-sm"]
@@ -103,7 +103,7 @@ def run(self) -> List[nodes.Node]:
103103

104104
info_column = create_component(
105105
"grid-item",
106-
["sd-col", "sd-d-flex", "sd-align-items-center"],
106+
["sd-col", "sd-d-flex-row", "sd-align-minor-center"],
107107
)
108108
self.set_source_info(info_column)
109109
top_row += info_column
@@ -138,7 +138,7 @@ def run(self) -> List[nodes.Node]:
138138
if author_text:
139139
author_column = create_component(
140140
"grid-item",
141-
["sd-col", "sd-col-auto", "sd-d-flex", "sd-align-items-center"],
141+
["sd-col", "sd-col-auto", "sd-d-flex-row", "sd-align-minor-center"],
142142
)
143143
self.set_source_info(author_column)
144144
author_nodes = self._parse_text(author_text, parse=parse_fields)
@@ -149,7 +149,7 @@ def run(self) -> List[nodes.Node]:
149149
if date_text:
150150
date_column = create_component(
151151
"grid-item",
152-
["sd-col", "sd-col-auto", "sd-d-flex", "sd-align-items-center"],
152+
["sd-col", "sd-col-auto", "sd-d-flex-row", "sd-align-minor-center"],
153153
)
154154
self.set_source_info(date_column)
155155
date_icon = nodes.raw(
@@ -166,7 +166,7 @@ def run(self) -> List[nodes.Node]:
166166
if read_time_text:
167167
read_time_column = create_component(
168168
"grid-item",
169-
["sd-col", "sd-col-auto", "sd-d-flex", "sd-align-items-center"],
169+
["sd-col", "sd-col-auto", "sd-d-flex-row", "sd-align-minor-center"],
170170
)
171171
self.set_source_info(read_time_column)
172172
read_time_icon = nodes.raw(

sphinx_design/compiled/style.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sphinx_design/dropdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def run(self):
172172
newnode = dropdown_main(
173173
opened=node["opened"],
174174
classes=["sd-sphinx-override", "sd-dropdown"]
175-
+ (["sd-card"] if use_card else ["sd-d-flex"])
175+
+ (["sd-card"] if use_card else ["sd-d-flex-column"])
176176
+ node["container_classes"],
177177
)
178178

sphinx_design/extension.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ def update_css_links(app: Sphinx, env: BuildEnvironment):
9393

9494
def visit_container(self, node: nodes.Node):
9595
classes = "docutils container"
96+
attrs = {}
9697
if node.get("is_div", False):
9798
# we don't want the CSS for container for these nodes
9899
classes = "docutils"
99-
self.body.append(self.starttag(node, "div", CLASS=classes))
100+
if "style" in node:
101+
attrs["style"] = node["style"]
102+
self.body.append(self.starttag(node, "div", CLASS=classes, **attrs))
100103

101104

102105
def depart_container(self, node: nodes.Node):
@@ -114,11 +117,10 @@ class Div(SphinxDirective):
114117

115118
optional_arguments = 1 # css classes
116119
final_argument_whitespace = True
117-
option_spec = {"name": directives.unchanged}
120+
option_spec = {"style": directives.unchanged, "name": directives.unchanged}
118121
has_content = True
119122

120123
def run(self):
121-
self.assert_has_content()
122124
try:
123125
if self.arguments:
124126
classes = directives.class_option(self.arguments[0])
@@ -130,9 +132,12 @@ def run(self):
130132
% (self.name, self.arguments[0])
131133
)
132134
node = create_component("div", rawtext="\n".join(self.content), classes=classes)
135+
if "style" in self.options:
136+
node["style"] = self.options["style"]
133137
self.set_source_info(node)
134138
self.add_name(node)
135-
self.state.nested_parse(self.content, self.content_offset, node)
139+
if self.content:
140+
self.state.nested_parse(self.content, self.content_offset, node)
136141
return [node]
137142

138143

sphinx_design/grids.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class GridDirective(SphinxDirective):
105105
"gutter": gutter_option,
106106
"margin": margin_option,
107107
"padding": padding_option,
108-
"text-align": text_align,
109108
"outline": directives.flag,
110109
"reverse": directives.flag,
111110
"class-container": directives.class_option,
@@ -129,7 +128,6 @@ def run(self) -> List[nodes.Node]:
129128
grid_classes
130129
+ self.options.get("margin", ["sd-mb-4"])
131130
+ self.options.get("padding", [])
132-
+ self.options.get("text-align", [])
133131
+ (["sd-border-1"] if "outline" in self.options else [])
134132
+ self.options.get("class-container", []),
135133
)
@@ -170,8 +168,9 @@ class GridItemDirective(SphinxDirective):
170168
"columns": item_columns_option,
171169
"margin": margin_option,
172170
"padding": padding_option,
171+
"child-direction": make_choice(["column", "row"]),
172+
"child-align": make_choice(["start", "end", "center", "justify", "spaced"]),
173173
"outline": directives.flag,
174-
"text-align": text_align,
175174
"class": directives.class_option,
176175
}
177176

@@ -188,12 +187,16 @@ def run(self) -> List[nodes.Node]:
188187
"grid-item",
189188
[
190189
"sd-col",
191-
"sd-d-flex", # TODO is this necessary or should be configurable?
190+
f"sd-d-flex-{self.options.get('child-direction', 'column')}",
192191
]
193192
+ self.options.get("columns", [])
194193
+ self.options.get("margin", [])
195194
+ self.options.get("padding", [])
196-
+ self.options.get("text-align", [])
195+
+ (
196+
[f'sd-align-major-{self.options["child-align"]}']
197+
if "child-align" in self.options
198+
else []
199+
)
197200
+ (["sd-border-1"] if "outline" in self.options else [])
198201
+ self.options.get("class", []),
199202
)
@@ -240,7 +243,7 @@ def run(self) -> List[nodes.Node]:
240243
"grid-item",
241244
[
242245
"sd-col",
243-
"sd-d-flex", # TODO is this necessary or should be configurable?
246+
"sd-d-flex-row",
244247
]
245248
+ self.options.get("columns", [])
246249
+ self.options.get("margin", [])

0 commit comments

Comments
 (0)