@ws-serenity/sass-styling 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ // https://github.com/KittyGiraudel/SassyJSON/tree/master/stylesheets/decode/helpers/color
2
+
3
+ @function hex-to-dec($string) {
4
+ $hex: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'd' 'e' 'f';
5
+ $string: to-lower-case($string);
6
+ $length: str-length($string);
7
+ $dec: 0;
8
+
9
+ @for $i from 1 through $length {
10
+ $factor: 1 + (15 * ($length - $i));
11
+ $index: index($hex, str-slice($string, $i, $i));
12
+ $dec: $dec + $factor * ($index - 1);
13
+ }
14
+
15
+ @return $dec;
16
+ }
17
+
18
+ @function regenerateColor($string) {
19
+ @if type-of($string) == 'color' {
20
+ @return $string;
21
+ }
22
+
23
+ $string-lower: to-lower-case($string);
24
+ $r: '';
25
+ $g: '';
26
+ $b: '';
27
+ $hex: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'd' 'e' 'f';
28
+ $length: str-length($string);
29
+ $max: if($length == 4, 1, 2);
30
+
31
+ @if $length != 4 and $length != 7 {
32
+ @return $string;
33
+ }
34
+
35
+ @for $i from 2 through $length {
36
+ $c: str-slice($string-lower, $i, $i);
37
+
38
+ @if index($hex, $c) == null {
39
+ @return $string;
40
+ }
41
+
42
+ @if str-length($r) < $max {
43
+ $r: $r + $c;
44
+ } @else if str-length($g) < $max {
45
+ $g: $g + $c;
46
+ } @else if str-length($b) < $max {
47
+ $b: $b + $c;
48
+ }
49
+ }
50
+
51
+ @if $length == 4 {
52
+ $r: $r + $r;
53
+ $g: $g + $g;
54
+ $b: $b + $b;
55
+ }
56
+
57
+ @return rgb(hex-to-dec($r), hex-to-dec($g), hex-to-dec($b));
58
+ }
@@ -0,0 +1,9 @@
1
+ @function str-replace($string, $search, $replace: '') {
2
+ $index: str-index($string, $search);
3
+
4
+ @if $index {
5
+ @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
6
+ }
7
+
8
+ @return $string;
9
+ }
@@ -0,0 +1,101 @@
1
+ @use 'sass:list';
2
+ @use 'sass:string';
3
+ @import './functions/strReplace';
4
+ @import './functions/regenerateColor';
5
+
6
+ @function get-color($color-name, $theme, $theme-colors, $group-name) {
7
+ @if string.index($color-name, '%') == 1 {
8
+ $group: map-get($theme, $group-name);
9
+ @return map-get($group, str-replace($color-name, '%'));
10
+ }
11
+ @return map-get($theme-colors, str-replace($color-name, '@', $group-name));
12
+ }
13
+
14
+ @function generate-theme-colors($theme, $theme-config) {
15
+ $theme-colors: ();
16
+
17
+ // Main
18
+ @each $group-name, $group in $theme-config {
19
+ $group-type: map-get($group, 'type');
20
+ $group-colors: map-get($group, 'colors');
21
+ @if $group-type == 'single' {
22
+ @each $shade-name, $shade-layers in $group-colors {
23
+ $color-rest: black;
24
+ $color-hover: black;
25
+ $color-active: black;
26
+ @for $i from 1 through list.length($shade-layers) {
27
+ $layer-config: list.nth($shade-layers, -$i);
28
+ $layer-color-name: list.nth($layer-config, 1);
29
+ $layer-color: get-color($layer-color-name, $theme, $theme-colors, $group-name);
30
+ $layer-color-state-modifiers: list.nth($layer-config, 2);
31
+ $rest-modifier: list.nth($layer-color-state-modifiers, 1);
32
+ $hover-modifier: $rest-modifier;
33
+ @if list.length($layer-color-state-modifiers) >= 2 {
34
+ $hover-modifier: list.nth($layer-color-state-modifiers, 2);
35
+ }
36
+ $active-modifier: $hover-modifier;
37
+ @if list.length($layer-color-state-modifiers) >= 3 {
38
+ $active-modifier: list.nth($layer-color-state-modifiers, 3);
39
+ }
40
+ $color-rest: mix($layer-color, $color-rest, $rest-modifier);
41
+ $color-hover: mix($layer-color, $color-hover, $hover-modifier);
42
+ $color-active: mix($layer-color, $color-active, $active-modifier);
43
+ }
44
+ $theme-colors: map-merge($theme-colors, (
45
+ '#{$group-name}-#{$shade-name}': $color-rest,
46
+ '#{$group-name}-#{$shade-name}-hover': $color-hover,
47
+ '#{$group-name}-#{$shade-name}-active': $color-active
48
+ ));
49
+ }
50
+ }
51
+ @if $group-type == 'foreach' {
52
+ @each $color-name, $_ in map-get($theme, $group-name) {
53
+ @each $shade-name, $shade-layers in $group-colors {
54
+ $color-rest: black;
55
+ $color-hover: black;
56
+ $color-active: black;
57
+ @for $i from 1 through list.length($shade-layers) {
58
+ $layer-config: list.nth($shade-layers, -$i);
59
+ $layer-color-name: list.nth($layer-config, 1);
60
+ $layer-color: get-color(
61
+ str-replace(
62
+ str-replace($layer-color-name, '%', '%#{$color-name}'),
63
+ '@',
64
+ '@#{$color-name}'
65
+ ),
66
+ $theme,
67
+ $theme-colors,
68
+ $group-name
69
+ );
70
+ $layer-color-state-modifiers: list.nth($layer-config, 2);
71
+ $rest-modifier: list.nth($layer-color-state-modifiers, 1);
72
+ $hover-modifier: $rest-modifier;
73
+ @if list.length($layer-color-state-modifiers) >= 2 {
74
+ $hover-modifier: list.nth($layer-color-state-modifiers, 2);
75
+ }
76
+ $active-modifier: $hover-modifier;
77
+ @if list.length($layer-color-state-modifiers) >= 3 {
78
+ $active-modifier: list.nth($layer-color-state-modifiers, 3);
79
+ }
80
+ $color-rest: mix($layer-color, $color-rest, $rest-modifier);
81
+ $color-hover: mix($layer-color, $color-hover, $hover-modifier);
82
+ $color-active: mix($layer-color, $color-active, $active-modifier);
83
+ }
84
+ $theme-colors: map-merge($theme-colors, (
85
+ '#{$group-name}#{$color-name}-#{$shade-name}': $color-rest,
86
+ '#{$group-name}#{$color-name}-#{$shade-name}-hover': $color-hover,
87
+ '#{$group-name}#{$color-name}-#{$shade-name}-active': $color-active
88
+ ));
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ // Overrides
95
+ $overrides: map-get($theme, 'overrides');
96
+ @each $color-name, $color-value in $overrides {
97
+ $theme-colors: map-merge($theme-colors, ($color-name: $color-value));
98
+ }
99
+
100
+ @return $theme-colors;
101
+ }
@@ -0,0 +1,38 @@
1
+ $weight-name-to-value-map: (
2
+ regular: 400,
3
+ semi-bold: 600,
4
+ bold: 700, // TODO DEAL WITH ME
5
+ );
6
+
7
+ $default-line-height-multiplier: 1.25;
8
+
9
+ @mixin set-font-css-vars(
10
+ $name,
11
+ $size,
12
+ $weight: regular,
13
+ $line-height: $size * $default-line-height-multiplier,
14
+ $letter-spacing: 0
15
+ ) {
16
+ --#{$name}-font-size: #{$size}px;
17
+ --#{$name}-line-height: #{$line-height};
18
+ --#{$name}-letter-spacing: #{$letter-spacing};
19
+
20
+ @if type-of($weight) == string {
21
+ --#{$name}-font-weight: #{map-get($weight-name-to-value-map, $weight)};
22
+ } @else {
23
+ --#{$name}-font-weight: #{$weight};
24
+ }
25
+ }
26
+
27
+ @mixin set-fonts-css-vars-by-map($map) {
28
+ @each $name, $size, $weight, $line-height, $letter-spacing in $map {
29
+ @include set-font-css-vars($name, $size, $weight, $line-height, $letter-spacing);
30
+ }
31
+ }
32
+
33
+ @mixin use-css-vars-based-font($name) {
34
+ font-size: var(--#{$name}-font-size);
35
+ line-height: var(--#{$name}-line-height);
36
+ letter-spacing: var(--#{$name}-letter-spacing);
37
+ font-weight: var(--#{$name}-font-weight);
38
+ }
@@ -0,0 +1,11 @@
1
+ @mixin max-width($resolution) {
2
+ @media (max-width: #{$resolution}px) {
3
+ @content;
4
+ }
5
+ }
6
+
7
+ @mixin min-width($resolution) {
8
+ @media (min-width: #{$resolution}px) {
9
+ @content;
10
+ }
11
+ }
@@ -0,0 +1,28 @@
1
+ %__flex {
2
+ display: flex;
3
+ }
4
+
5
+ %__flex-column {
6
+ flex-direction: column;
7
+ }
8
+
9
+ @mixin flex-column($gap:null) {
10
+ @extend %__flex;
11
+ @extend %__flex-column;
12
+
13
+ @if ($gap != null) {
14
+ row-gap: $gap;
15
+ }
16
+ }
17
+
18
+ @mixin flex($gap:null) {
19
+ @extend %__flex;
20
+
21
+ @if ($gap != null) {
22
+ column-gap: $gap;
23
+ }
24
+ }
25
+
26
+ %margin-center {
27
+ margin: 0 auto;
28
+ }
@@ -0,0 +1,24 @@
1
+ %__background-alpha {
2
+ &::before {
3
+ content: '';
4
+ width: 100%;
5
+ height: 100%;
6
+ position: absolute;
7
+ left: 0;
8
+ z-index: -1;
9
+ }
10
+ }
11
+
12
+ @mixin background-alpha($color, $alpha) {
13
+ @extend %__background-alpha;
14
+
15
+ &::before {
16
+ background-color: $color;
17
+ opacity: $alpha;
18
+ }
19
+ }
20
+
21
+ %border-radius-max {
22
+ // таким образом получается добиться максимального радиуса скругления, а не круглого элемента
23
+ border-radius: 9999px;
24
+ }
@@ -0,0 +1,14 @@
1
+ @mixin color-svg($color) {
2
+ color: $color;
3
+
4
+ svg {
5
+ fill: $color;
6
+ }
7
+ }
8
+
9
+ @mixin size-svg($height, $width: $height) {
10
+ svg {
11
+ height: $height;
12
+ width: $width;
13
+ }
14
+ }
@@ -0,0 +1,19 @@
1
+ %__multiline-ellipsis-overflow {
2
+ display: -webkit-box;
3
+ overflow: hidden;
4
+ text-overflow: ellipsis;
5
+ -webkit-box-orient: vertical;
6
+ }
7
+
8
+ @mixin multiline-ellipsis-overflow($lines-amount) {
9
+ @extend %__multiline-ellipsis-overflow;
10
+
11
+ -webkit-line-clamp: $lines-amount;
12
+ line-clamp: $lines-amount;
13
+ }
14
+
15
+ %text-overflow-ellipsis {
16
+ white-space: nowrap;
17
+ overflow: hidden;
18
+ text-overflow: ellipsis;
19
+ }
@@ -0,0 +1,77 @@
1
+ * {
2
+ padding: 0;
3
+ margin: 0;
4
+ border: 0;
5
+ }
6
+
7
+ *, *::before, *::after {
8
+ box-sizing: border-box;
9
+ }
10
+
11
+ :focus, :active {
12
+ outline: none;
13
+ }
14
+
15
+ a,
16
+ a:visited,
17
+ a:hover {
18
+ text-decoration: none;
19
+ color: unset;
20
+ }
21
+
22
+ a:focus, a:active {
23
+ outline: none;
24
+ }
25
+
26
+ nav, footer, header, aside {
27
+ display: block;
28
+ }
29
+
30
+ html, body, #root {
31
+ overflow-x: hidden;
32
+ height: 100%;
33
+ width: 100%;
34
+ line-height: 1;
35
+ font-size: 14px;
36
+ text-size-adjust: 100%;
37
+ -webkit-tap-highlight-color: transparent;
38
+ scroll-behavior: smooth;
39
+ overscroll-behavior: none;
40
+ }
41
+
42
+ input, button, textarea {
43
+ font-family: inherit;
44
+ outline: none !important;
45
+ box-shadow: none;
46
+ }
47
+
48
+ input {
49
+ color: inherit;
50
+
51
+ &::-ms-clear {
52
+ display: none;
53
+ }
54
+ }
55
+
56
+ button::-moz-focus-inner {
57
+ padding: 0;
58
+ border: 0;
59
+ }
60
+
61
+ ul li {
62
+ list-style: none;
63
+ }
64
+
65
+ img {
66
+ vertical-align: top;
67
+ }
68
+
69
+ h1, h2, h3, h4, h5, h6 {
70
+ font-size: inherit;
71
+ font-weight: 400;
72
+ }
73
+
74
+ button {
75
+ background-color: inherit;
76
+ cursor: pointer;
77
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@ws-serenity/sass-styling",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "directories": {
6
+ "lib": "lib"
7
+ },
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "peerDependencies": {
12
+ "sass": "1.55.0"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC"
17
+ }
package/readme.md ADDED
@@ -0,0 +1,78 @@
1
+ ## About
2
+
3
+ Библиотека базовых sass-стилей
4
+
5
+ ## Sass
6
+
7
+ Папка не обладает сайд-эффектами, ее можно импортировать сколько угодно
8
+
9
+ ## Side-effect
10
+
11
+ Импортировать эти файлы необходимо единожды! Иначе возникнет дублирование стилей
12
+
13
+ ## Generator
14
+
15
+ ### Палитры
16
+ ```scss
17
+ @import '@ws-serenity/sass-styling/lib/generator/colors';
18
+
19
+ // for $themes and $themes-config declaration check storybook
20
+
21
+ @mixin create-css-themes-root() {
22
+ @each $theme-name, $theme in $themes {
23
+ $theme-colors: generate-theme-colors($theme, $theme-config);
24
+
25
+ &.#{$theme-name}-theme {
26
+ @each $color-name, $color-value in $theme-colors {
27
+ --#{$color-name}: #{$color-value}
28
+ }
29
+ }
30
+ }
31
+ }
32
+ ```
33
+
34
+ ### Шрифтов
35
+
36
+ ```scss
37
+ @import '@ws-serenity/sass-styling/lib/generator/fonts';
38
+
39
+ // for full example check storybook
40
+
41
+ :root {
42
+ // 1. declare css-vars
43
+ @include set-fonts-css-vars-by-map((
44
+ // @formatter:off
45
+ heading-1 50 bold 140% -0.03em,
46
+ body-1 18 regular 140% -0.03em,
47
+ // @formatter:on
48
+ ));
49
+
50
+ // 2. declare font and use in as placeholder, combined with mixin
51
+ %font-family-roboto {
52
+ font-family: 'Roboto', sans-serif;
53
+ }
54
+ @mixin use-font($name) {
55
+ @extend %font-family-roboto;
56
+ // 2.5 call special mixin from library, to set css-vars
57
+ @include use-css-vars-based-font($name);
58
+ }
59
+
60
+ // 3. declare placeholders and just use mixin above
61
+ %heading-1 {
62
+ @include use-font(heading-1);
63
+ }
64
+
65
+ %body-1 {
66
+ @include use-font(body-1);
67
+ }
68
+
69
+ // 4. declare the styles
70
+ .body-1 {
71
+ @extend %body-1;
72
+ }
73
+
74
+ .heading-1 {
75
+ @extend %heading-1;
76
+ }
77
+ }
78
+ ```