@greensight/gds
Version:
Greensight Design System
110 lines (100 loc) • 3.74 kB
JavaScript
const helpers = [
` getProperty($name, $value) {
$value {
#{$name}: $value;
}
}`,
` defaultPropertyFn($property) {
$property;
}`,
` cssProperty($propertyName, $propertyValue, $fn: defaultPropertyFn) {
meta.type-of($propertyValue) == 'map' {
$size, $value in $propertyValue {
$size == breakpoints.$defaultBreakpoint {
getProperty($propertyName, meta.call(meta.get-function($fn), $value));
}
$size != breakpoints.$defaultBreakpoint {
mq(map.get(breakpoints.$breakpointList, $size)) {
getProperty($propertyName, meta.call(meta.get-function($fn), $value));
}
}
}
} {
getProperty($propertyName, meta.call(meta.get-function($fn), $propertyValue));
}
}`,
].join('\n');
const funcsFormMixins = [
` gridLayoutCellFn($property) {
meta.type-of($property) == 'number' {
math.unit($property) == 'px' {
$property;
} {
repeat($property, 1fr);
}
}
meta.type-of($property) == 'list' {
list.join($property, (), $separator: space);
}
meta.type-of($property) == 'string' {
$property;
}
null;
}`,
` layoutGapFn($property) {
meta.type-of($property) == 'string' {
$property;
}
meta.type-of($property) == 'list' and list.length($property) == 2 {
list.join($property, (), $separator: space);
}
null;
}`,
` gridLayoutItemCellFn($property) {
meta.type-of($property) == 'list' and list.length($property) == 2 {
#{list.nth($property, 1)} / #{list.nth($property, 2)};
}
$property {
#{span $property};
}
null;
}`,
].join('\n');
const mixins = [
` gridLayout($cols: 12, $gap: gs(3)) {
display: grid;
cssProperty('grid-template-columns', $cols, gridLayoutCellFn);
cssProperty('gap', $gap, layoutGapFn);
}`,
` gridLayoutRows($rows) {
cssProperty('grid-template-rows', $rows, gridLayoutCellFn);
}`,
` alignmentLayout($justify, $align) {
cssProperty('justify-items', $justify);
cssProperty('align-items', $align);
}`,
` gridLayoutItem($col: false, $row: false) {
cssProperty('grid-column', $col, gridLayoutItemCellFn);
cssProperty('grid-row', $row, gridLayoutItemCellFn);
}`,
` alignmentLayoutItem($justify: false, $align: false) {
cssProperty('justify-self', $justify);
cssProperty('align-self', $align);
}`,
` orderLayoutItem($order) {
cssProperty('order', $order);
}`,
` flexLayout($gap) {
display: flex;
cssProperty('gap', $gap, layoutGapFn);
}`,
` section($mb: false, $padding: false, $bg: false) {
cssProperty('margin-bottom', $mb);
cssProperty('padding', $padding);
cssProperty('background-color', $bg);
}`,
].join('\n');
const getLayoutMixin = () => {
return [helpers, funcsFormMixins, mixins].join('\n');
};
module.exports = { getLayoutMixin };