Skip to content

Commit 84cd405

Browse files
committed
✨ Add support for CSS customization
1 parent 6f562d7 commit 84cd405

Some content is hidden

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

52 files changed

+1366
-666
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ yarn add webcoreui
7979

8080
### Setup
8181

82-
Setup default styles and fonts by calling the following in your global SCSS file:
82+
Create an empty `webcore.config.scss` file at the root of your project to setup CSS configurations. Setup default styles and fonts by calling the following in your global SCSS file:
8383

8484
```scss
8585
@import 'webcoreui/styles';
86-
@include Setup((
86+
@include setup((
8787
// Define paths for your fonts
8888
fontRegular: '/fonts/Inter-Regular.woff2',
8989
fontBold: '/fonts/Inter-Bold.woff2'
@@ -100,14 +100,13 @@ The `Setup` mixin can also accept the following options:
100100
|-----------|---------------|---------|
101101
| `includeResets` | `true` | Include reset styles. Set to `false` if you want to use your own CSS resets. |
102102
| `includeHelperClasses` | `true` | Adds global helper classes for CSS. All global helper classes are defined [here](https://github.com/Frontendland/webcoreui/tree/main/src/scss/global). |
103-
| `includeElementStyles` | `true` | Adds styles for native HTML elements, such as `code`, `pre`, or `ul`.
104103
| `includeTooltip` | `true` | Adds styles for using tooltips.
105104
| `includeScrollbarStyles` | `true` | Adds styles for scrollbars.
106105

107106
Default component styles can be changed by overriding the following CSS variables:
108107

109-
```css
110-
body {
108+
```scss
109+
html body {
111110
--w-avatar-border: var(--w-color-primary-70);
112111
--w-checkbox-color: var(--w-color-primary);
113112
--w-progress-color: var(--w-color-primary);
@@ -134,6 +133,12 @@ body {
134133
--w-timeline-counter: decimal;
135134
--w-tooltip-background: var(--w-color-primary);
136135
--w-tooltip-color: var(--w-color-primary-70);
136+
137+
// Override border-radius
138+
--w-sm-radius: 2px;
139+
--w-md-radius: 5px;
140+
--w-lg-radius: 10px;
141+
--w-xl-radius: 15px;
137142
}
138143
```
139144

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"utils",
3737
"astro.d.ts",
3838
"astro.js",
39+
"icons.d.ts",
40+
"icons.js",
3941
"svelte.d.ts",
4042
"svelte.js",
4143
"react.d.ts",

scripts/build.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const files = {
1515
'package.json': 'dist/package.json'
1616
}
1717

18+
const sassConfig = 'dist/scss/config.scss'
19+
1820
console.log('🚀 Preparing package build')
1921

2022
if (!fs.existsSync('dist')) {
@@ -26,6 +28,12 @@ Object.keys(folders).forEach(key => {
2628
if (error) {
2729
console.error('🚨 error copying directory', error)
2830
}
31+
32+
if (key.includes('scss')) {
33+
const configFile = fs.readFileSync(sassConfig, 'utf-8')
34+
35+
fs.writeFileSync(sassConfig, configFile.replace('../../webcore', '../webcore'))
36+
}
2937
})
3038
})
3139

@@ -49,5 +57,4 @@ fs.writeFileSync('dist/svelte.d.ts', buildTypes('svelte'))
4957
fs.writeFileSync('dist/react.d.ts', buildTypes('react'))
5058
fs.writeFileSync('dist/icons.d.ts', buildTypes('icons'))
5159

52-
5360
console.log('✅ Package built')
Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
1-
@import '../../scss/config.scss';
1+
@use '../../scss/config.scss' as *;
22

33
.accordion {
4-
margin: 0;
5-
padding: 0;
4+
@include spacing(0);
65
list-style-type: none;
76

87
li {
9-
border-bottom: 1px solid var(--w-color-primary-50);
10-
padding: 10px 0;
11-
font-size: 16px;
8+
@include border(primary-50, bottom);
9+
@include spacing(py-sm, px-none, m0);
10+
@include typography(md);
1211

1312
&:first-child {
1413
padding-top: 0;
1514
}
1615

1716
&:last-child {
18-
border-bottom: 0;
17+
@include border(bottom, 0);
1918
padding-bottom: 0;
2019
}
2120

2221
.title {
23-
display: flex;
24-
justify-content: space-between;
25-
align-items: center;
26-
gap: 10px;
27-
width: 100%;
22+
@include layout(flex, h-between, v-center, sm);
23+
@include typography(md, primary, left);
24+
@include size('w100%');
25+
@include spacing(p0);
26+
@include border(0);
27+
2828
background: transparent;
29-
border: 0;
30-
color: var(--w-color-primary);
31-
font-size: 16px;
32-
padding: 0;
3329
cursor: pointer;
34-
text-align: left;
3530

3631
svg {
37-
@include Transition(transform);
38-
color: var(--w-color-primary-20);
39-
width: 15px;
40-
height: 15px;
32+
@include transition(transform);
33+
@include size(15px);
34+
@include typography(primary-20);
4135
pointer-events: none;
4236
}
4337

@@ -50,22 +44,22 @@
5044
grid-template-rows: 1fr;
5145

5246
.content {
53-
padding: 10px 0;
47+
@include spacing(py-sm, px-none);
5448
}
5549
}
5650
}
5751
}
5852

5953
.wrapper {
60-
@include Transition(grid-template-rows);
61-
display: grid;
54+
@include transition(grid-template-rows);
55+
@include layout(grid);
6256
grid-template-rows: 0fr;
6357
}
6458

6559
.content {
66-
@include Transition();
67-
overflow: hidden;
68-
color: var(--w-color-primary-20);
60+
@include transition();
61+
@include visibility(hidden);
62+
@include typography(primary-20);
6963
}
7064
}
7165
}
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
1-
@import '../../scss/config.scss';
1+
@use '../../scss/config.scss' as *;
22

33
.w-alert {
4-
border: 1px solid var(--w-color-primary-50);
5-
border-radius: 5px;
6-
padding: 15px;
7-
display: flex;
4+
@include border(primary-50);
5+
@include border-radius(md);
6+
@include spacing(p-md);
7+
@include layout(flex);
88

99
&.col {
10-
flex-direction: column;
10+
@include layout(column);
1111
}
1212

1313
&:not(.col) {
14-
gap: 10px;
14+
@include layout(sm);
1515
}
1616

1717
&.info {
18-
border: 1px solid var(--w-color-info);
19-
color: var(--w-color-info);
18+
@include border(info);
19+
@include typography(info);
2020
}
2121

2222
&.success {
23-
border: 1px solid var(--w-color-success);
24-
color: var(--w-color-success);
23+
@include border(success);
24+
@include typography(success);
2525
}
2626

2727
&.warning {
28-
border: 1px solid var(--w-color-warning);
29-
color: var(--w-color-warning);
28+
@include border(warning);
29+
@include typography(warning);
3030
}
3131

3232
&.alert {
33-
border: 1px solid var(--w-color-alert);
34-
color: var(--w-color-alert);
33+
@include border(alert);
34+
@include typography(alert);
3535
}
3636

3737
svg {
38-
width: 20px;
39-
height: 20px;
38+
@include size(20px);
4039
min-width: 20px;
4140
margin-top: 1px;
4241
}
4342

4443
.title {
44+
@include spacing(mb-xs);
4545
display: block;
46-
margin-bottom: 5px;
4746
}
4847

4948
.body {
50-
font-size: 16px;
51-
color: var(--w-color-primary-20);
52-
line-height: 1.5;
49+
@include typography(primary-20, md, hmd);
5350
}
5451
}

src/components/Avatar/avatar.module.scss

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
@import '../../scss/config.scss';
1+
@use '../../scss/config.scss' as *;
2+
3+
body {
4+
--w-avatar-border: var(--w-color-primary-70);
5+
}
26

37
.avatar {
4-
border-radius: 100%;
8+
@include border-radius(max);
59

610
&:not(.borderless) {
711
border: 3px solid var(--w-avatar-border);
812
}
913
}
1014

1115
.group {
12-
display: inline-flex;
13-
align-items: center;
16+
@include layout(inline-flex, v-center);
1417

1518
&.reverse {
16-
flex-direction: row-reverse;
19+
@include layout(row-reverse);
1720

1821
img {
19-
z-index: 1;
22+
@include layer(fg);
2023
}
2124

2225
img:not(:first-child) {
Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,86 @@
1-
@import '../../scss/config.scss';
1+
@use '../../scss/config.scss' as *;
22

33
.badge {
4-
@include Transition();
5-
padding: 5px 10px;
6-
border-radius: 5px;
7-
display: inline-flex;
8-
align-items: center;
9-
gap: 5px;
10-
font-size: 12px;
11-
background: var(--w-color-primary);
12-
color: var(--w-color-primary-50);
13-
border: 0;
4+
@include transition();
5+
@include spacing(py-xs, px-sm);
6+
@include border-radius(xs);
7+
@include layout(inline-flex, v-center, xs);
8+
@include typography(xs, primary-50);
9+
@include border(0);
10+
@include background(primary);
1411

1512
&.hover {
1613
cursor: pointer;
1714

1815
&:hover {
19-
background: var(--w-color-primary-20);
16+
@include background(primary-20);
2017
}
2118

2219
&.secondary:hover {
23-
background: var(--w-color-primary-40);
20+
@include background(primary-40);
2421
}
2522

2623
&.outline:hover {
27-
color: var(--w-color-primary);
28-
background: transparent;
24+
@include typography(primary);
25+
@include background(transparent);
2926
box-shadow: inset 0px 0px 0px 1px var(--w-color-primary);
3027
}
3128

3229
&.flat:hover {
33-
background: var(--w-color-primary-40);
30+
@include background(primary-40);
3431
}
3532

3633
&.info:hover {
37-
background: var(--w-color-info-accent);
34+
@include background(info-accent);
3835
}
3936

4037
&.success:hover {
41-
background: var(--w-color-success-accent);
38+
@include background(success-accent);
4239
}
4340

4441
&.warning:hover {
45-
background: var(--w-color-warning-accent);
42+
@include background(warning-accent);
4643
}
4744

4845
&.alert:hover {
49-
background: var(--w-color-alert-accent);
46+
@include background(alert-accent);
5047
}
5148
}
5249

5350

5451
&.secondary {
55-
background: var(--w-color-primary-50);
56-
color: var(--w-color-primary);
52+
@include typography(primary);
53+
@include background(primary-50);
5754
}
5855

5956
&.outline {
60-
background: var(--w-color-primary-70);
61-
color: var(--w-color-primary-20);
57+
@include typography(primary-20);
58+
@include background(primary-70);
6259
box-shadow: inset 0px 0px 0px 1px var(--w-color-primary-20);
6360
}
6461

6562
&.flat {
66-
background: var(--w-color-primary-70);
67-
color: var(--w-color-primary);
63+
@include typography(primary);
64+
@include background(primary-70);
6865
}
6966

7067
&.info {
71-
background: var(--w-color-info);
72-
color: var(--w-color-info-fg);
68+
@include typography(info-fg);
69+
@include background(info);
7370
}
7471

7572
&.success {
76-
background: var(--w-color-success);
77-
color: var(--w-color-success-fg);
73+
@include typography(success-fg);
74+
@include background(success);
7875
}
7976

8077
&.warning {
81-
background: var(--w-color-warning);
82-
color: var(--w-color-warning-fg);
78+
@include typography(warning-fg);
79+
@include background(warning);
8380
}
8481

8582
&.alert {
86-
background: var(--w-color-alert);
87-
color: var(--w-color-alert-fg);
83+
@include typography(alert-fg);
84+
@include background(alert);
8885
}
8986
}

0 commit comments

Comments
 (0)