Skip to content

Commit ccbb2cb

Browse files
pkp/pkp-lib#10850 Add CSS Variables derived from Tailwind config
1 parent 9766004 commit ccbb2cb

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

.storybook/preview.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import VueScrollTo from 'vue-scrollto';
2929

3030
import '../src/styles/_import.less';
3131
import '../src/styles/_global.less';
32+
import '../src/styles/style.css';
3233
import {allModes} from './modes';
3334
import {initialize, mswLoader} from 'msw-storybook-addon';
3435

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Meta, Story, ArgTypes} from '@storybook/blocks';
2+
import * as _CSSVariablesStories from './_CSSVariables.stories.js';
3+
4+
<Meta title="Guide/Style/CSS Variables" />
5+
6+
# Css Variables
7+
8+
List of CSS variables that you can use directly when designing a plugin. These variables are derived from Tailwind's utility classes, specifically based on our theme configuration.
9+
10+
<Story of={_CSSVariablesStories.Default} />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import CssVariables from './_CSSVariables.vue';
2+
3+
export default {
4+
title: 'DocsHelpers/CSS Variables',
5+
component: CssVariables,
6+
};
7+
8+
export const Default = () => ({
9+
components: {CssVariables},
10+
template: '<CssVariables />',
11+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<template>
2+
<table class="min-w-full divide-y divide-light">
3+
<tr class="">
4+
<th class="text-left rtl:text-right">Variable</th>
5+
<th class="px-2 text-left rtl:text-right">Value</th>
6+
</tr>
7+
<tr v-for="(variable, index) in cssVariables" :key="index">
8+
<td class="whitespace-nowrap rtl:text-right" dir="ltr">
9+
{{ variable.name }}
10+
</td>
11+
<td class="inline-flex p-2">
12+
<div
13+
v-if="variable.styles"
14+
class="h-6 w-6"
15+
:style="variable.styles"
16+
></div>
17+
<span class="px-1" dir="ltr">{{ variable.value }}</span>
18+
</td>
19+
</tr>
20+
</table>
21+
</template>
22+
23+
<script setup>
24+
import {ref, onMounted} from 'vue';
25+
26+
const cssVariables = ref([]);
27+
28+
onMounted(() => {
29+
const vars = [];
30+
31+
for (const sheet of document.styleSheets) {
32+
try {
33+
for (const rule of sheet.cssRules) {
34+
if (rule.style) {
35+
let primaryColor;
36+
for (let i = 0; i < rule.style.length; i++) {
37+
const prop = rule.style[i];
38+
if (prop.startsWith('--') && !prop.startsWith('--tw')) {
39+
const value = rule.style.getPropertyValue(prop).trim();
40+
41+
if (prop === '--background-color-primary') {
42+
primaryColor = value;
43+
}
44+
let styles;
45+
if (prop.includes('color')) {
46+
styles = {
47+
backgroundColor: value,
48+
};
49+
} else if (prop.includes('shadow')) {
50+
styles = {
51+
boxShadow: value,
52+
borderRadius: '1px',
53+
};
54+
} else if (prop.includes('radius')) {
55+
styles = {
56+
backgroundColor: primaryColor,
57+
borderRadius: value,
58+
};
59+
}
60+
61+
vars.push({
62+
name: prop,
63+
value,
64+
styles,
65+
});
66+
}
67+
}
68+
}
69+
}
70+
} catch (error) {
71+
console.warn('Cannot get all the stylesheets on the page.', error);
72+
}
73+
}
74+
75+
cssVariables.value = vars;
76+
});
77+
</script>

src/styles/_global.less

-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@
3131
@import 'variables';
3232
@import 'helpers';
3333
@import 'elements/screen-reader';
34-
@import (css) 'style.css';

0 commit comments

Comments
 (0)