Refactor on styled-system
parent
b7a8c2fff4
commit
83506ea4e8
|
@ -7,15 +7,15 @@ export const getDeclaration = (property, value) => {
|
||||||
.join('');
|
.join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const importantRegex = /.*!$/;
|
||||||
|
|
||||||
export const token = {
|
export const token = {
|
||||||
spacing: (property, options) => {
|
spacing: (property, options) => {
|
||||||
return {
|
return {
|
||||||
type: 'spacing',
|
type: 'spacing',
|
||||||
property,
|
property,
|
||||||
transform(value) {
|
transform(value) {
|
||||||
console.log(this.key);
|
return importantRegex.test(value) ? value + 'important' : value;
|
||||||
|
|
||||||
return value;
|
|
||||||
},
|
},
|
||||||
toString(value, options) {
|
toString(value, options) {
|
||||||
return getDeclaration(property, this.transform(value));
|
return getDeclaration(property, this.transform(value));
|
||||||
|
@ -36,22 +36,28 @@ export const token = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createRules = (rules = {}) => {
|
export const defineDeclarations = (data = {}) => {
|
||||||
return Object.entries(rules).reduce((acc, [key, value]) => ((acc[key] = { key, ...value }), acc), {});
|
return Object.entries(data).reduce((acc, [key, value]) => ((acc[key] = { key, ...value }), acc), {});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createStyleData = (rules = {}) => {
|
export const useDeclarations = (...args) => {
|
||||||
const keys = Object.keys(rules);
|
const declarations = Object.assign({}, ...args);
|
||||||
|
const keys = Object.keys(declarations);
|
||||||
const props = keys.reduce((acc, k) => ((acc[k] = undefined), acc), {});
|
const props = keys.reduce((acc, k) => ((acc[k] = undefined), acc), {});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
rules,
|
|
||||||
keys,
|
keys,
|
||||||
props,
|
props,
|
||||||
toString(obj) {
|
declarations,
|
||||||
return Object.entries(obj)
|
getStyleDeclarations(options) {},
|
||||||
|
filterP(_props) {
|
||||||
|
const __props = Object.entries(_props)
|
||||||
.filter(([key]) => keys.includes(key))
|
.filter(([key]) => keys.includes(key))
|
||||||
.reduce((acc, [key, value]) => {
|
.reduce((acc, [k, v]) => ((acc[k] = v), acc), {});
|
||||||
|
const __ks = Object.keys(__props);
|
||||||
|
const __declarations = Object.entries(__props).reduce((acc, [key]) => ((acc[key] = declarations[key]), acc), {});
|
||||||
|
|
||||||
|
/*const declarations = props.reduce((acc, [key, value]) => {
|
||||||
if (ObjectUtils.isNotEmpty(value)) {
|
if (ObjectUtils.isNotEmpty(value)) {
|
||||||
const rule = ObjectUtils.toKebabCase(key);
|
const rule = ObjectUtils.toKebabCase(key);
|
||||||
|
|
||||||
|
@ -60,7 +66,26 @@ export const createStyleData = (rules = {}) => {
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, [])
|
}, [])
|
||||||
|
.join('');*/
|
||||||
|
|
||||||
|
return {
|
||||||
|
keys: __ks,
|
||||||
|
props: __props,
|
||||||
|
declarations: __declarations,
|
||||||
|
getStyleDeclarations(options) {
|
||||||
|
return Object.entries(__declarations)
|
||||||
|
.reduce((acc, [, value]) => {
|
||||||
|
const { key, toString } = value;
|
||||||
|
|
||||||
|
const v = __props[key];
|
||||||
|
|
||||||
|
ObjectUtils.isNotEmpty(v) && acc.push(value.toString(v, options));
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, [])
|
||||||
.join('');
|
.join('');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { defineDeclarations, token } from '..';
|
||||||
import x from './modules/x';
|
import x from './modules/x';
|
||||||
import y from './modules/y';
|
import y from './modules/y';
|
||||||
import bottom from './properties/bottom';
|
import bottom from './properties/bottom';
|
||||||
|
@ -6,6 +7,10 @@ import right from './properties/right';
|
||||||
import top from './properties/top';
|
import top from './properties/top';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
...defineDeclarations({
|
||||||
|
padding: token.spacing('padding'),
|
||||||
|
p: token.spacing('padding')
|
||||||
|
}),
|
||||||
// properties
|
// properties
|
||||||
...bottom,
|
...bottom,
|
||||||
...left,
|
...left,
|
||||||
|
@ -16,33 +21,3 @@ export default {
|
||||||
...x,
|
...x,
|
||||||
...y
|
...y
|
||||||
};
|
};
|
||||||
|
|
||||||
/* const { styleClass } = require('../../utils');
|
|
||||||
const bottom = require('./properties/bottom');
|
|
||||||
const left = require('./properties/left');
|
|
||||||
const right = require('./properties/right');
|
|
||||||
const top = require('./properties/top');
|
|
||||||
const x = require('./modules/x');
|
|
||||||
const y = require('./modules/y');
|
|
||||||
|
|
||||||
module.exports = (root, opts) => {
|
|
||||||
const scales = opts.spacing;
|
|
||||||
let paddings = {};
|
|
||||||
|
|
||||||
for (const i in scales) {
|
|
||||||
paddings['p-' + i] = scales[i] + 'rem';
|
|
||||||
}
|
|
||||||
|
|
||||||
styleClass('padding', paddings, root, opts, true);
|
|
||||||
|
|
||||||
// properties
|
|
||||||
bottom(root, opts);
|
|
||||||
left(root, opts);
|
|
||||||
right(root, opts);
|
|
||||||
top(root, opts);
|
|
||||||
|
|
||||||
// modules
|
|
||||||
x(root, opts);
|
|
||||||
y(root, opts);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,20 +1,6 @@
|
||||||
import { createRules, token } from '../..';
|
import { defineDeclarations, token } from '../..';
|
||||||
|
|
||||||
export default createRules({
|
export default defineDeclarations({
|
||||||
paddingX: token.spacing(['paddingLeft', 'paddingRight']),
|
paddingX: token.spacing(['paddingLeft', 'paddingRight']),
|
||||||
px: token.spacing(['paddingLeft', 'paddingRight'])
|
px: token.spacing(['paddingLeft', 'paddingRight'])
|
||||||
});
|
});
|
||||||
|
|
||||||
/* const { styleClass } = require('../../../utils');
|
|
||||||
|
|
||||||
module.exports = (root, opts) => {
|
|
||||||
const scales = opts.spacing;
|
|
||||||
let xPaddings = {};
|
|
||||||
|
|
||||||
for (const i in scales) {
|
|
||||||
xPaddings['px-' + i] = scales[i] + 'rem';
|
|
||||||
}
|
|
||||||
|
|
||||||
styleClass(['padding-left', 'padding-right'], xPaddings, root, opts, true);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,20 +1,6 @@
|
||||||
import { createRules, token } from '../..';
|
import { defineDeclarations, token } from '../..';
|
||||||
|
|
||||||
export default createRules({
|
export default defineDeclarations({
|
||||||
paddingX: token.spacing(['paddingTop', 'paddingBottom']),
|
paddingX: token.spacing(['paddingTop', 'paddingBottom']),
|
||||||
px: token.spacing(['paddingTop', 'paddingBottom'])
|
px: token.spacing(['paddingTop', 'paddingBottom'])
|
||||||
});
|
});
|
||||||
|
|
||||||
/* const { styleClass } = require('../../../utils');
|
|
||||||
|
|
||||||
module.exports = (root, opts) => {
|
|
||||||
const scales = opts.spacing;
|
|
||||||
let yPaddings = {};
|
|
||||||
|
|
||||||
for (const i in scales) {
|
|
||||||
yPaddings['py-' + i] = scales[i] + 'rem';
|
|
||||||
}
|
|
||||||
|
|
||||||
styleClass(['padding-top', 'padding-bottom'], yPaddings, root, opts, true);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,20 +1,6 @@
|
||||||
import { createRules, token } from '../..';
|
import { defineDeclarations, token } from '../..';
|
||||||
|
|
||||||
export default createRules({
|
export default defineDeclarations({
|
||||||
paddingBottom: token.spacing('paddingBottom'),
|
paddingBottom: token.spacing('paddingBottom'),
|
||||||
pb: token.spacing('paddingBottom')
|
pb: token.spacing('paddingBottom')
|
||||||
});
|
});
|
||||||
|
|
||||||
/* const { styleClass } = require('../../../utils');
|
|
||||||
|
|
||||||
module.exports = (root, opts) => {
|
|
||||||
const scales = opts.spacing;
|
|
||||||
let bottomPaddings = {};
|
|
||||||
|
|
||||||
for (const i in scales) {
|
|
||||||
bottomPaddings['pb-' + i] = `${scales[i]}rem`;
|
|
||||||
}
|
|
||||||
|
|
||||||
styleClass('padding-bottom', bottomPaddings, root, opts, true);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,20 +1,6 @@
|
||||||
import { createRules, token } from '../..';
|
import { defineDeclarations, token } from '../..';
|
||||||
|
|
||||||
export default createRules({
|
export default defineDeclarations({
|
||||||
paddingLeft: token.spacing('paddingLeft'),
|
paddingLeft: token.spacing('paddingLeft'),
|
||||||
pl: token.spacing('paddingLeft')
|
pl: token.spacing('paddingLeft')
|
||||||
});
|
});
|
||||||
|
|
||||||
/* const { styleClass } = require('../../../utils');
|
|
||||||
|
|
||||||
module.exports = (root, opts) => {
|
|
||||||
const scales = opts.spacing;
|
|
||||||
let leftPaddings = {};
|
|
||||||
|
|
||||||
for (const i in scales) {
|
|
||||||
leftPaddings['pl-' + i] = `${scales[i]}rem`;
|
|
||||||
}
|
|
||||||
|
|
||||||
styleClass('padding-left', leftPaddings, root, opts, true);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,20 +1,6 @@
|
||||||
import { createRules, token } from '../..';
|
import { defineDeclarations, token } from '../..';
|
||||||
|
|
||||||
export default createRules({
|
export default defineDeclarations({
|
||||||
paddingRight: token.spacing('paddingRight'),
|
paddingRight: token.spacing('paddingRight'),
|
||||||
pr: token.spacing('paddingRight')
|
pr: token.spacing('paddingRight')
|
||||||
});
|
});
|
||||||
|
|
||||||
/* const { styleClass } = require('../../../utils');
|
|
||||||
|
|
||||||
module.exports = (root, opts) => {
|
|
||||||
const scales = opts.spacing;
|
|
||||||
let rightPaddings = {};
|
|
||||||
|
|
||||||
for (const i in scales) {
|
|
||||||
rightPaddings['pr-' + i] = `${scales[i]}rem`;
|
|
||||||
}
|
|
||||||
|
|
||||||
styleClass('padding-right', rightPaddings, root, opts, true);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,20 +1,6 @@
|
||||||
import { createRules, token } from '../..';
|
import { defineDeclarations, token } from '../..';
|
||||||
|
|
||||||
export default createRules({
|
export default defineDeclarations({
|
||||||
paddingTop: token.spacing('paddingTop'),
|
paddingTop: token.spacing('paddingTop'),
|
||||||
pt: token.spacing('paddingTop')
|
pt: token.spacing('paddingTop')
|
||||||
});
|
});
|
||||||
|
|
||||||
/* const { styleClass } = require('../../../utils');
|
|
||||||
|
|
||||||
module.exports = (root, opts) => {
|
|
||||||
const scales = opts.spacing;
|
|
||||||
let topPaddings = {};
|
|
||||||
|
|
||||||
for (const i in scales) {
|
|
||||||
topPaddings['pt-' + i] = `${scales[i]}rem`;
|
|
||||||
}
|
|
||||||
|
|
||||||
styleClass('padding-top', topPaddings, root, opts, true);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
import BaseComponent from 'primevue/basecomponent';
|
import BaseComponent from 'primevue/basecomponent';
|
||||||
import TextStyle from 'primevue/text/style';
|
import TextStyle from 'primevue/text/style';
|
||||||
import { createStyleData } from '../props/style';
|
import { useDeclarations } from '../props/style';
|
||||||
import SPACING from '../props/style/spacing.js';
|
import SPACING from '../props/style/spacing.js';
|
||||||
|
|
||||||
export const styleData = createStyleData(SPACING);
|
export const styleData = useDeclarations(SPACING);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BaseText',
|
name: 'BaseText',
|
||||||
|
|
|
@ -41,7 +41,7 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
styles() {
|
styles() {
|
||||||
return styleData.toString(this.$props);
|
return styleData.filterP(this.$props).getStyleDeclarations(this.$config.theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</DocSectionText>
|
</DocSectionText>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<Panel header="Header">
|
<Panel header="Header">
|
||||||
<Text px="0">
|
<Text px="0!" p="1px">
|
||||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||||
</Text>
|
</Text>
|
||||||
|
|
Loading…
Reference in New Issue