Skip to content

Commit

Permalink
Merge pull request #330 from woylie/refine-stack
Browse files Browse the repository at this point in the history
refine stack
  • Loading branch information
woylie authored Jul 24, 2024
2 parents 67100b6 + a2805bf commit 282c375
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 61 deletions.
54 changes: 0 additions & 54 deletions demo/assets/css/_extends.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,3 @@
*/

@use "functions" as f;

/// Applies a vertical margin between the child elements.
///
/// @example
/// .some-component {
/// @extend %stack;
/// }
///
/// This layout can also be applied with the `.stack` class (see layouts/stack).
%stack {
display: flex;
flex-direction: column;
justify-content: flex-start;

& > * {
margin-block: 0;
}

& > * + * {
margin-block-start: var(--space, f.lines(1));
}

&.is-recursive {
& * {
margin-block: 0;
}

& * + * {
margin-block-start: var(--space, f.lines(1));
}
}

/*
You can add modifiers like this:
&.is-small > * + * {
margin-top: var(--space, f.lines(0.5));
}
Or you can add exceptions like this:
& > .some-component + * {
margin-top: var(--space, f.lines(1.5));
}
This would apply a different margin between `.some-component` and the next
element. Alternatively, you could also change the margin between some
component and the previous element:
& > * + .some-component {
margin-top: var(--space, f.lines(1.5));
}
*/
}
46 changes: 44 additions & 2 deletions demo/assets/css/layouts/_stack.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,50 @@
* Applies a vertical margin between the child elements.
*/

@use "../extends";
@use "../functions" as f;

.stack {
@extend %stack;
display: flex;
flex-direction: column;
justify-content: flex-start;

& > * {
margin-block: 0;
}

& > * + * {
margin-block-start: var(--space, f.lines(1));
}

&.is-recursive {
& * {
margin-block: 0;
}

& * + * {
margin-block-start: var(--space, f.lines(1));
}
}

/*
You can add modifiers like this:
&.is-small > * + * {
margin-top: var(--space, f.lines(0.5));
}
Or you can add exceptions like this:
& > .some-component + * {
margin-top: var(--space, f.lines(1.5));
}
This would apply a different margin between `.some-component` and the next
element. Alternatively, you could also change the margin between some
component and the previous element:
& > * + .some-component {
margin-top: var(--space, f.lines(1.5));
}
*/
}
11 changes: 6 additions & 5 deletions lib/doggo/components/stack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ defmodule Doggo.Components.Stack do
</.stack>
```
To apply a vertical margin on nested elements as well, set `recursive` to
`true`.
By default, the margin is only applied to the direct children of the
component. To apply a vertical margin on children at any nesting level, set
the `recursive` attribute.
```heex
<.stack recursive={true}>
<.stack recursive>
<div>
<div>some nested block</div>
<div>another nested block</div>
Expand All @@ -42,7 +43,7 @@ defmodule Doggo.Components.Stack do
[
type: :layout,
since: "0.6.0",
maturity: :refining,
maturity: :stable,
modifiers: [],
extra: [recursive_class: "is-recursive"]
]
Expand All @@ -54,7 +55,7 @@ defmodule Doggo.Components.Stack do
attr :recursive, :boolean,
default: false,
doc:
"If `true`, the stack margins will be applied to nested elements as well."
"If `true`, the stack margins will be applied to nested children as well."

attr :rest, :global, doc: "Any additional HTML attributes."

Expand Down
2 changes: 2 additions & 0 deletions lib/doggo/storybook/stack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ defmodule Doggo.Storybook.Stack do
[
%Variation{
id: :default,
description: "Default (margin only applied to direct children)",
slots: slots()
},
%Variation{
id: :recursive,
description: "Recursive (margin applied to nested children)",
attributes: %{recursive: true},
slots: recursive_slots()
}
Expand Down

0 comments on commit 282c375

Please sign in to comment.