1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-16 11:14:26 +07:00
verdaccio-ui/src/utils/styles/mixings.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-02-03 17:23:33 +07:00
/**
* CSS to represent truncated text with an ellipsis.
*/
2019-06-22 16:43:59 +07:00
export function ellipsis(width: string | number): {} {
2019-02-03 17:23:33 +07:00
return {
display: 'inline-block',
maxWidth: width,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
wordWrap: 'normal',
};
}
/**
* Shorthand that accepts up to four values, including null to skip a value, and maps them to their respective directions.
*/
interface SpacingShortHand<type> {
top?: type;
right?: type;
bottom?: type;
left?: type;
}
const positionMap = ['Top', 'Right', 'Bottom', 'Left'];
2019-06-22 16:43:59 +07:00
export function spacing(property: 'padding' | 'margin', ...values: SpacingShortHand<number | string>[]): {} {
2019-02-03 17:23:33 +07:00
const [firstValue = 0, secondValue = 0, thirdValue = 0, fourthValue = 0] = values;
const valuesWithDefaults = [firstValue, secondValue, thirdValue, fourthValue];
let styles = {};
for (let i = 0; i < valuesWithDefaults.length; i += 1) {
if (valuesWithDefaults[i] || valuesWithDefaults[i] === 0) {
styles = {
...styles,
[`${property}${positionMap[i]}`]: valuesWithDefaults[i],
};
}
}
return styles;
}