Skip to content

Commit

Permalink
Refactor space generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Oct 27, 2023
1 parent 72888cc commit 53d3790
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 142 deletions.
11 changes: 11 additions & 0 deletions .storybook/storybook.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,14 @@
.tna-picture--demo {
max-width: 480px;
}

.tna-spacing-demo {
p {
padding-right: 0.5rem;
padding-left: 0.5rem;

@include colour.colour-background("background-tint");

// @include colour.colour-border("keyline", 1px, solid, top);
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Initial concept of text detail elements
- Elements can be hidden on certain devices with `tna-!--hide-on-[large|medium|small|tiny]`

### Changed

- `tna-visually-hidden` changed to `tna-!--visually-hidden`
- Changed Node version from `lts/hydrogen` to `lts/iron`
- Update the `spacing` and `spacing-mobile` functions in `spacing` to `space` and `space-mobile`

### Deprecated
### Removed
Expand Down
2 changes: 1 addition & 1 deletion src/nationalarchives/components/gallery/gallery.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
display: flex;
flex-direction: column;
align-items: center;
gap: spacing.spacing("l");
gap: spacing.space("l");

&:focus {
outline: none !important;
Expand Down
47 changes: 27 additions & 20 deletions src/nationalarchives/stories/utilities/overrides/overrides.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,49 @@ import * as OverrideStories from './overrides.stories';

# Overrides

## Properties
## Options

Property options: `margin`, `padding`
`property`:

```css
tna-!--no-[property]-[direction]
```
- `margin`
- `padding`

### No margin/padding

Direction options:
`direction`:

- `top`
- `bottom`
- `vertical` - `top` and `bottom`

```css
## Removing space

```
// For all devices
tna-!--no-[property]-[direction]
```

### Sizes
`device` options (optional):

Size options: `xs`, `s`, `m`, `l`, `xl`, `xxl`
- `large`
- `medium`
- `small`
- `tiny`

```css
tna-!--[property]-[direction]-[size]
```

### Responsive

Device options: `medium`, `small`, `tiny`

```css
// For a specific device size
tna-!--no-[property]-[direction]-[device]
tna-!--[property]-[direction]-[size]-[device]
```

## Adding space

`size` options:

- `xs`
- `s`
- `m`
- `l`
- `xl`
- `xxl`

```css
tna-!--[property]-[direction]-[size]
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ export default {
};

const Template = () => {
return `<p>Lorem ipsum</p>
return `<div class="tna-spacing-demo">
<p>Lorem ipsum</p>
<p class="tna-!--no-margin-top">Lorem ipsum (tna-!--no-margin-top)</p>
<p class="tna-!--margin-top-xs">Lorem ipsum (tna-!--margin-top-xs)</p>
<p class="tna-!--margin-top-s">Lorem ipsum (tna-!--margin-top-s)</p>
<p class="tna-!--margin-top-m">Lorem ipsum (tna-!--margin-top-m)</p>
<p class="tna-!--margin-top-l">Lorem ipsum (tna-!--margin-top-l)</p>
<p class="tna-!--margin-top-xl">Lorem ipsum (tna-!--margin-top-xl)</p>`;
<p class="tna-!--margin-top-xl">Lorem ipsum (tna-!--margin-top-xl)</p>
<p class="tna-!--margin-top-xxl">Lorem ipsum (tna-!--margin-top-xxl)</p>
</div>`;
};

export const Margin = Template.bind({});
Expand Down
93 changes: 91 additions & 2 deletions src/nationalarchives/tools/_spacing.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use "sass:map";
@use "../variables/spacing";
@use "../tools/media";

%space-above {
margin-top: 2rem;
Expand All @@ -13,10 +14,98 @@
@extend %space-above;
}

@function spacing($size) {
@function space($size) {
@return map.get(spacing.$spacing, $size);
}

@function spacing-mobile($size) {
@function space-mobile($size) {
@return map.get(spacing.$spacing-mobile, $size);
}

@mixin no-spacing-generator($suffix: "") {
@if $suffix != "" {
$suffix: "-" + $suffix;
}
@each $property in margin, padding {
@each $direction in top, bottom {
$combined-direction: "";
@if $direction == top or $direction == bottom {
$combined-direction: vertical;
} @else if $direction == right or $direction == left {
$combined-direction: horizontal;
}
@if $combined-direction {
.tna-\!--no-#{$property}-#{$direction}#{$suffix},
.tna-\!--no-#{$property}-#{$combined-direction}#{$suffix} {
#{$property}-#{$direction}: 0 !important;
}
} @else {
.tna-\!--no-#{$property}-#{$direction}#{$suffix} {
#{$property}-#{$direction}: 0 !important;
}
}
}
}
}

@mixin spacing-generator($suffix: "") {
@each $property in margin, padding {
@each $direction in top, bottom {
@each $size, $amount in spacing.$spacing {
@if $direction == all {
.tna-\!--#{$property}-#{$size} {
#{$property}: #{$amount} !important;
}
} @else {
$combined-direction: "";
@if $direction == top or $direction == bottom {
$combined-direction: vertical;
} @else if $direction == right or $direction == left {
$combined-direction: horizontal;
}
@if $combined-direction {
.tna-\!--#{$property}-#{$direction}-#{$size},
.tna-\!--#{$property}-#{$combined-direction}-#{$size} {
#{$property}-#{$direction}: #{$amount} !important;
}
} @else {
.tna-\!--#{$property}-#{$direction}-#{$size} {
#{$property}-#{$direction}: #{$amount} !important;
}
}
}
}
}
}

@include media.on-mobile {
@each $property in margin, padding {
@each $direction in top, bottom {
@each $size, $amount in spacing.$spacing-mobile {
@if $direction == all {
.tna-\!--#{$property}-#{$size} {
#{$property}: #{$amount} !important;
}
} @else {
$combined-direction: "";
@if $direction == top or $direction == bottom {
$combined-direction: vertical;
} @else if $direction == right or $direction == left {
$combined-direction: horizontal;
}
@if $combined-direction {
.tna-\!--#{$property}-#{$direction}-#{$size},
.tna-\!--#{$property}-#{$combined-direction}-#{$size} {
#{$property}-#{$direction}: #{$amount} !important;
}
} @else {
.tna-\!--#{$property}-#{$direction}-#{$size} {
#{$property}-#{$direction}: #{$amount} !important;
}
}
}
}
}
}
}
}
121 changes: 13 additions & 108 deletions src/nationalarchives/utilities/_overrides.scss
Original file line number Diff line number Diff line change
@@ -1,127 +1,32 @@
@use "sass:map";
@use "../variables/spacing";
@use "../tools/media";
@use "../tools/spacing";

@mixin no-spacing-generator($suffix: "") {
@if $suffix != "" {
$suffix: "-" + $suffix;
}

@each $property in margin, padding {
@each $direction in top, bottom {
$combined-direction: "";
@if $direction == top or $direction == bottom {
$combined-direction: vertical;
} @else if $direction == right or $direction == left {
$combined-direction: horizontal;
}
@if $combined-direction {
.tna-\!--no-#{$property}-#{$direction}#{$suffix},
.tna-\!--no-#{$property}-#{$combined-direction}#{$suffix} {
#{$property}-#{$direction}: 0 !important;
}
} @else {
.tna-\!--no-#{$property}-#{$direction}#{$suffix} {
#{$property}-#{$direction}: 0 !important;
}
}
}
}
}

@mixin hide($suffix) {
.tna-\!--hide-#{$suffix} {
@mixin hide-on($suffix) {
.tna-\!--hide-on-#{$suffix} {
display: none;
}
}

@include no-spacing-generator;

@each $property in margin, padding {
@each $direction in top, bottom {
@each $size, $amount in spacing.$spacing {
@if $direction == all {
.tna-\!--#{$property}-#{$size} {
#{$property}: #{$amount} !important;

@include media.on-mobile {
#{$property}: #{map.get(spacing.$spacing-mobile, $size)} !important;
}
}
} @else {
$combined-direction: "";
@if $direction == top or $direction == bottom {
$combined-direction: vertical;
} @else if $direction == right or $direction == left {
$combined-direction: horizontal;
}
@if $combined-direction {
.tna-\!--#{$property}-#{$direction}-#{$size},
.tna-\!--#{$property}-#{$combined-direction}-#{$size} {
#{$property}-#{$direction}: #{$amount} !important;
}
} @else {
.tna-\!--#{$property}-#{$direction}-#{$size} {
#{$property}-#{$direction}: #{$amount} !important;
}
}
}
}
}
}

@include media.on-mobile {
@each $property in margin, padding {
@each $direction in top, bottom {
@each $size, $amount in spacing.$spacing {
@if $direction == all {
.tna-\!--#{$property}-#{$size} {
#{$property}: #{map.get(spacing.$spacing-mobile, $size)} !important;
}
} @else {
$combined-direction: "";
@if $direction == top or $direction == bottom {
$combined-direction: vertical;
} @else if $direction == right or $direction == left {
$combined-direction: horizontal;
}
@if $combined-direction {
.tna-\!--#{$property}-#{$direction}-#{$size},
.tna-\!--#{$property}-#{$combined-direction}-#{$size} {
#{$property}-#{$direction}: #{map.get(
spacing.$spacing-mobile,
$size
)} !important;
}
} @else {
.tna-\!--#{$property}-#{$direction}-#{$size} {
#{$property}-#{$direction}: #{map.get(
spacing.$spacing-mobile,
$size
)} !important;
}
}
}
}
}
}
}
@include spacing.no-spacing-generator;
@include spacing.spacing-generator;

@include media.on-large {
@include hide("large");
@include spacing.no-spacing-generator("large");
@include hide-on("large");
}

@include media.on-medium {
@include no-spacing-generator("medium");
@include hide("medium");
@include spacing.no-spacing-generator("medium");
@include hide-on("medium");
}

@include media.on-small {
@include no-spacing-generator("small");
@include hide("small");
@include spacing.no-spacing-generator("small");
@include hide-on("small");
}

@include media.on-tiny {
@include no-spacing-generator("tiny");
@include hide("tiny");
@include spacing.no-spacing-generator("tiny");
@include hide-on("tiny");
}
Loading

0 comments on commit 53d3790

Please sign in to comment.