Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@toptal/picasso-container

Package Overview
Dependencies
Maintainers
0
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toptal/picasso-container - npm Package Compare versions

Comparing version 1.0.4-alpha-fx-null-fix-tag-7b2900a3d.25 to 2.0.0

dist-package/src/Container/utils/constants.d.ts

67

dist-package/src/Container/Container.js

@@ -12,20 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {

};
import { makeStyles } from '@material-ui/core/styles';
import { makeResponsiveSpacingProps } from '@toptal/picasso-provider';
import cx from 'classnames';
import React from 'react';
import { documentable, forwardRef, kebabToCamelCase } from '@toptal/picasso-utils';
import styles from './styles';
import { filterOutStringAndPicassoSpacing, getBaseSpacingClasses, } from './utils';
const useStyles = makeStyles(styles, {
name: 'PicassoContainer',
});
const useResponsiveProps = makeResponsiveSpacingProps([
'margin-top',
'margin-bottom',
'margin-left',
'margin-right',
'padding',
'gap',
], 'PicassoContainer-Responsive');
import { documentable, forwardRef } from '@toptal/picasso-utils';
import { twMerge } from '@toptal/picasso-tailwind-merge';
import { alignmentClasses, variantClassesByColor } from './styles';
import { getSpacingClasses, getSpacingStyles } from './utils';
/**

@@ -38,31 +25,19 @@ * Container component used for spacing 2 elements

/* eslint-disable @typescript-eslint/no-unused-vars */
classes: externalClasses } = props,
/* eslint-enable */
rest = __rest(props, ["children", "className", "inline", "flex", "direction", "alignItems", "justifyContent", "style", "bordered", "rounded", "variant", "align", "as", "top", "bottom", "left", "right", "padded", "gap", "classes"]);
const classes = useStyles(props);
const { className: responsiveClasses, style: responsiveStyle } = useResponsiveProps({
'margin-top': filterOutStringAndPicassoSpacing(top),
'margin-bottom': filterOutStringAndPicassoSpacing(bottom),
'margin-left': filterOutStringAndPicassoSpacing(left),
'margin-right': filterOutStringAndPicassoSpacing(right),
padding: filterOutStringAndPicassoSpacing(padded),
gap: filterOutStringAndPicassoSpacing(gap),
});
const baseSpacingClasses = getBaseSpacingClasses({ top, left, bottom, right, gap, padded }, classes);
return (React.createElement(Component, Object.assign({}, rest, { ref: ref, className: cx(classes[`${variant}Variant`], {
[classes[`${padded}Padding`]]: typeof padded === 'string',
[classes[`${gap}Gap`]]: typeof gap === 'string',
[classes[`top${top}Margin`]]: typeof top === 'string',
[classes[`bottom${bottom}Margin`]]: typeof bottom === 'string',
[classes[`left${left}Margin`]]: typeof left === 'string',
[classes[`right${right}Margin`]]: typeof right === 'string',
[classes[`${align}TextAlign`]]: typeof align === 'string',
[classes[`${kebabToCamelCase(alignItems || '')}AlignItems`]]: alignItems,
[classes[`${kebabToCamelCase(justifyContent || '')}JustifyContent`]]: justifyContent,
[classes.bordered]: bordered,
[classes.rounded]: rounded,
[classes.flex]: flex,
[classes.inline]: inline,
[classes[kebabToCamelCase(direction || '')]]: direction && direction !== 'row',
}, baseSpacingClasses, responsiveClasses, className), style: Object.assign(Object.assign({}, responsiveStyle), style) }), children));
classes: externalClasses } = props, rest = __rest(props, ["children", "className", "inline", "flex", "direction", "alignItems", "justifyContent", "style", "bordered", "rounded", "variant", "align", "as", "top", "bottom", "left", "right", "padded", "gap", "classes"]);
const spacingProps = { gap, padded, top, bottom, right, left };
const isBorderedVariant = !variant || variant === 'white' || variant === 'transparent';
const getDisplayValue = (isInline, isFlex) => {
return isFlex
? isInline
? 'inline-flex'
: 'flex'
: isInline
? 'inline-block'
: '';
};
return (React.createElement(Component, Object.assign({}, rest, { ref: ref, className: twMerge(variant && variantClassesByColor[variant], getSpacingClasses(spacingProps), typeof align === 'string' && alignmentClasses.textAlign[align], alignItems && alignmentClasses.alignItems[alignItems], justifyContent && alignmentClasses.justifyContent[justifyContent], bordered &&
isBorderedVariant &&
'border border-solid border-gray-200', rounded && 'rounded-md', getDisplayValue(inline, flex), direction &&
direction !== 'row' &&
alignmentClasses.direction[direction], className), style: Object.assign(Object.assign({}, getSpacingStyles(spacingProps)), style) }), children));
}));

@@ -69,0 +44,0 @@ Container.displayName = 'Container';

@@ -1,2 +0,1 @@

import type { Theme } from '@material-ui/core/styles';
declare const alignItemsVariants: readonly ["flex-start", "flex-end", "center", "stretch", "baseline"];

@@ -8,4 +7,33 @@ declare const justifyContentVariants: readonly ["flex-start", "flex-end", "center", "space-between", "space-around", "space-evenly"];

export declare type JustifyContentType = (typeof justifyContentVariants)[number];
declare const _default: ({ palette, sizes: { borderRadius } }: Theme) => import("@material-ui/styles").StyleRules<{}, string>;
export default _default;
export declare const alignmentClasses: {
readonly alignItems: {
readonly 'flex-start': "items-start";
readonly 'flex-end': "items-end";
readonly center: "items-center";
readonly stretch: "items-stretch";
readonly baseline: "items-baseline";
};
readonly textAlign: {
readonly inherit: "[text-align:inherit]";
readonly left: "text-left";
readonly center: "text-center";
readonly right: "text-right";
readonly justify: "text-justify";
};
readonly justifyContent: {
readonly center: "justify-center";
readonly 'flex-start': "justify-start";
readonly 'flex-end': "justify-end";
readonly 'space-between': "justify-between";
readonly 'space-around': "justify-around";
readonly 'space-evenly': "justify-evenly";
};
readonly direction: {
readonly column: "flex-col";
readonly 'row-reverse': "flex-row-reverse";
readonly 'column-reverse': "flex-col-reverse";
};
};
export declare const variantClassesByColor: Record<VariantType, string>;
export {};
//# sourceMappingURL=styles.d.ts.map

@@ -1,11 +0,1 @@

import { createStyles } from '@material-ui/core/styles';
import { capitalize } from '@material-ui/core';
import { spacingToRem, spacings, kebabToCamelCase, snakeToCamelCase, } from '@toptal/picasso-provider';
const textAlignVariants = [
'inherit',
'left',
'center',
'right',
'justify',
];
const alignItemsVariants = [

@@ -35,103 +25,40 @@ 'flex-start',

];
const colorVariant = (colorOptions) => {
var _a;
if (!colorOptions) {
return {};
}
return {
backgroundColor: (_a = colorOptions.lighter2) !== null && _a !== void 0 ? _a : colorOptions.lighter,
};
export const alignmentClasses = {
alignItems: {
'flex-start': 'items-start',
'flex-end': 'items-end',
center: 'items-center',
stretch: 'items-stretch',
baseline: 'items-baseline',
},
textAlign: {
inherit: '[text-align:inherit]',
left: 'text-left',
center: 'text-center',
right: 'text-right',
justify: 'text-justify',
},
justifyContent: {
center: 'justify-center',
'flex-start': 'justify-start',
'flex-end': 'justify-end',
'space-between': 'justify-between',
'space-around': 'justify-around',
'space-evenly': 'justify-evenly',
},
direction: {
column: 'flex-col',
'row-reverse': 'flex-row-reverse',
'column-reverse': 'flex-col-reverse',
},
};
const directionVariants = ['top', 'left', 'bottom', 'right'];
const spacingVariants = [
'xsmall',
'small',
'medium',
'large',
'xlarge',
];
const paddings = spacingVariants.reduce((acc, variant) => {
acc[`${variant}Padding`] = {
padding: spacingToRem(variant),
};
return acc;
}, Object.create(null));
const basePaddings = Object.keys(spacings).reduce((acc, spacingKey) => {
acc[`${snakeToCamelCase(spacingKey)}Padding`] = {
padding: spacingToRem(spacings[spacingKey]),
};
return acc;
}, Object.create(null));
const gaps = spacingVariants.reduce((acc, variant) => {
acc[`${variant}Gap`] = {
gap: spacingToRem(variant),
};
return acc;
}, Object.create(null));
const baseGaps = Object.keys(spacings).reduce((acc, spacingKey) => {
acc[`${snakeToCamelCase(spacingKey)}Gap`] = {
gap: spacingToRem(spacings[spacingKey]),
};
return acc;
}, Object.create(null));
const marginClassDef = (direction, spacing) => ({
[`margin${capitalize(direction)}`]: spacingToRem(spacing),
});
const marginClasses = (direction) => {
return {
[`${direction}${'xsmall'}Margin`]: marginClassDef(direction, 'xsmall'),
[`${direction}${'small'}Margin`]: marginClassDef(direction, 'small'),
[`${direction}${'medium'}Margin`]: marginClassDef(direction, 'medium'),
[`${direction}${'large'}Margin`]: marginClassDef(direction, 'large'),
[`${direction}${'xlarge'}Margin`]: marginClassDef(direction, 'xlarge'),
};
export const variantClassesByColor = {
white: 'bg-white',
red: 'bg-red-100 border border-solid border-red-150',
green: 'bg-green-100 border border-solid border-green-150',
yellow: 'bg-yellow-100 border border-solid border-yellow-150',
blue: 'bg-blue-100 border border-solid border-blue-150',
grey: 'bg-gray-200 border border-solid border-gray-400',
transparent: '',
};
const baseMarginClasses = (direction) => {
return Object.keys(spacings).reduce((acc, spacingKey) => {
acc[`${direction}${snakeToCamelCase(spacingKey, true)}Margin`] = {
[`margin${capitalize(direction)}`]: spacingToRem(spacings[spacingKey]),
};
return acc;
}, Object.create(null));
};
const margins = Object.assign(Object.assign(Object.assign(Object.assign({}, marginClasses('top')), marginClasses('left')), marginClasses('bottom')), marginClasses('right'));
const baseMargins = Object.assign(Object.assign(Object.assign(Object.assign({}, baseMarginClasses('top')), baseMarginClasses('left')), baseMarginClasses('bottom')), baseMarginClasses('right'));
const alignItems = {};
alignItemsVariants.forEach(variant => {
alignItems[`${kebabToCamelCase(variant)}AlignItems`] = {
alignItems: variant,
};
});
const textAlignItems = {};
textAlignVariants.forEach(variant => {
textAlignItems[`${variant}TextAlign`] = {
textAlign: variant,
};
});
const justifyContent = {};
justifyContentVariants.forEach(variant => {
justifyContent[`${kebabToCamelCase(variant)}JustifyContent`] = {
justifyContent: variant,
};
});
export default ({ palette, sizes: { borderRadius } }) => createStyles(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ bordered: {
border: `1px solid ${palette.grey.lighter2}`,
}, rounded: {
borderRadius: borderRadius.medium,
}, flex: {
display: 'flex',
'&$inline': {
display: 'inline-flex',
},
}, column: {
flexDirection: 'column',
}, rowReverse: {
flexDirection: 'row-reverse',
}, columnReverse: {
flexDirection: 'column-reverse',
}, inline: {
display: 'inline-block',
}, whiteVariant: {
backgroundColor: palette.common.white,
}, redVariant: colorVariant(palette.red), greenVariant: colorVariant(palette.green), yellowVariant: colorVariant(palette.yellow), blueVariant: colorVariant(palette.blue), greyVariant: colorVariant(palette.grey) }, paddings), basePaddings), margins), baseMargins), alignItems), justifyContent), textAlignItems), gaps), baseGaps));
//# sourceMappingURL=styles.js.map

@@ -1,3 +0,3 @@

export { default as getBaseSpacingClasses } from './get-base-spacing-classes';
export { default as filterOutStringAndPicassoSpacing } from './filter-out-strings-and-picasso-spacings';
export * from './get-spacing-classes';
//# sourceMappingURL=index.d.ts.map

@@ -1,3 +0,3 @@

export { default as getBaseSpacingClasses } from './get-base-spacing-classes';
export { default as filterOutStringAndPicassoSpacing } from './filter-out-strings-and-picasso-spacings';
export * from './get-spacing-classes';
//# sourceMappingURL=index.js.map
{
"name": "@toptal/picasso-container",
"version": "1.0.4-alpha-fx-null-fix-tag-7b2900a3d.25+7b2900a3d",
"version": "2.0.0",
"description": "Toptal UI components library - Container",

@@ -29,13 +29,13 @@ "homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso#readme",

"dependencies": {
"@toptal/picasso-utils": "1.0.4-alpha-fx-null-fix-tag-7b2900a3d.25+7b2900a3d",
"classnames": "^2.5.1"
"@toptal/picasso-utils": "1.0.3"
},
"peerDependencies": {
"@material-ui/core": "4.12.4",
"@toptal/picasso-provider": "*",
"@toptal/picasso-tailwind": ">=2.7",
"@toptal/picasso-tailwind-merge": "^1.1.1",
"react": ">=16.12.0 < 19.0.0"
},
"devDependencies": {
"@toptal/picasso-provider": "4.2.2-alpha-fx-null-fix-tag-7b2900a3d.33+7b2900a3d",
"@toptal/picasso-test-utils": "1.1.2-alpha-fx-null-fix-tag-7b2900a3d.25+7b2900a3d"
"@toptal/picasso-provider": "5.0.0",
"@toptal/picasso-test-utils": "1.1.1"
},

@@ -49,4 +49,3 @@ "publishConfig": {

"src"
],
"gitHead": "7b2900a3d34f5627022f65bf3cbaa23b53aa48b8"
]
}

@@ -1,23 +0,1 @@

import type { Theme } from '@material-ui/core/styles'
import { createStyles } from '@material-ui/core/styles'
import type { Color } from '@material-ui/core';
import { capitalize } from '@material-ui/core'
import type { SimplePaletteColorOptions } from '@material-ui/core/styles/createPalette'
import {
spacingToRem,
type DeprecatedSpacingType,
type PicassoSpacing,
spacings,
kebabToCamelCase,
snakeToCamelCase,
} from '@toptal/picasso-provider'
const textAlignVariants = [
'inherit',
'left',
'center',
'right',
'justify',
] as const
const alignItemsVariants = [

@@ -53,178 +31,41 @@ 'flex-start',

export type JustifyContentType = (typeof justifyContentVariants)[number]
type MapOfClasses = Record<string, Record<string, string>>
const colorVariant = (colorOptions?: SimplePaletteColorOptions | Color) => {
if (!colorOptions) {
return {}
}
export const alignmentClasses = {
alignItems: {
'flex-start': 'items-start',
'flex-end': 'items-end',
center: 'items-center',
stretch: 'items-stretch',
baseline: 'items-baseline',
},
textAlign: {
inherit: '[text-align:inherit]',
left: 'text-left',
center: 'text-center',
right: 'text-right',
justify: 'text-justify',
},
justifyContent: {
center: 'justify-center',
'flex-start': 'justify-start',
'flex-end': 'justify-end',
'space-between': 'justify-between',
'space-around': 'justify-around',
'space-evenly': 'justify-evenly',
},
direction: {
column: 'flex-col',
'row-reverse': 'flex-row-reverse',
'column-reverse': 'flex-col-reverse',
},
} as const
return {
backgroundColor: colorOptions.lighter2 ?? colorOptions.lighter,
}
export const variantClassesByColor: Record<VariantType, string> = {
white: 'bg-white',
red: 'bg-red-100 border border-solid border-red-150',
green: 'bg-green-100 border border-solid border-green-150',
yellow: 'bg-yellow-100 border border-solid border-yellow-150',
blue: 'bg-blue-100 border border-solid border-blue-150',
grey: 'bg-gray-200 border border-solid border-gray-400',
transparent: '',
}
const directionVariants = ['top', 'left', 'bottom', 'right'] as const
const spacingVariants = [
'xsmall',
'small',
'medium',
'large',
'xlarge',
] as const
type Direction = (typeof directionVariants)[number]
type Spacing = (typeof spacingVariants)[number]
const paddings = spacingVariants.reduce((acc, variant) => {
acc[`${variant}Padding`] = {
padding: spacingToRem(variant as DeprecatedSpacingType),
}
return acc
}, Object.create(null))
const basePaddings = Object.keys(spacings).reduce((acc, spacingKey) => {
acc[`${snakeToCamelCase(spacingKey)}Padding`] = {
padding: spacingToRem(spacings[spacingKey] as PicassoSpacing),
}
return acc
}, Object.create(null))
const gaps = spacingVariants.reduce((acc, variant) => {
acc[`${variant}Gap`] = {
gap: spacingToRem(variant as DeprecatedSpacingType),
}
return acc
}, Object.create(null))
const baseGaps = Object.keys(spacings).reduce((acc, spacingKey) => {
acc[`${snakeToCamelCase(spacingKey)}Gap`] = {
gap: spacingToRem(spacings[spacingKey] as PicassoSpacing),
}
return acc
}, Object.create(null))
const marginClassDef = (direction: Direction, spacing: Spacing) => ({
[`margin${capitalize(direction)}`]: spacingToRem(spacing),
})
const marginClasses = (direction: Direction) => {
return {
[`${direction}${'xsmall'}Margin`]: marginClassDef(direction, 'xsmall'),
[`${direction}${'small'}Margin`]: marginClassDef(direction, 'small'),
[`${direction}${'medium'}Margin`]: marginClassDef(direction, 'medium'),
[`${direction}${'large'}Margin`]: marginClassDef(direction, 'large'),
[`${direction}${'xlarge'}Margin`]: marginClassDef(direction, 'xlarge'),
}
}
const baseMarginClasses = (direction: Direction) => {
return Object.keys(spacings).reduce((acc, spacingKey) => {
acc[`${direction}${snakeToCamelCase(spacingKey, true)}Margin`] = {
[`margin${capitalize(direction)}`]: spacingToRem(spacings[spacingKey]),
}
return acc
}, Object.create(null))
}
const margins: MapOfClasses = {
...marginClasses('top'),
...marginClasses('left'),
...marginClasses('bottom'),
...marginClasses('right'),
}
const baseMargins: MapOfClasses = {
...baseMarginClasses('top'),
...baseMarginClasses('left'),
...baseMarginClasses('bottom'),
...baseMarginClasses('right'),
}
const alignItems: MapOfClasses = {}
alignItemsVariants.forEach(variant => {
alignItems[`${kebabToCamelCase(variant)}AlignItems`] = {
alignItems: variant,
}
})
const textAlignItems: MapOfClasses = {}
textAlignVariants.forEach(variant => {
textAlignItems[`${variant}TextAlign`] = {
textAlign: variant,
}
})
const justifyContent: MapOfClasses = {}
justifyContentVariants.forEach(variant => {
justifyContent[`${kebabToCamelCase(variant)}JustifyContent`] = {
justifyContent: variant,
}
})
export default ({ palette, sizes: { borderRadius } }: Theme) =>
createStyles({
bordered: {
border: `1px solid ${palette.grey.lighter2}`,
},
rounded: {
borderRadius: borderRadius.medium,
},
flex: {
display: 'flex',
'&$inline': {
display: 'inline-flex',
},
},
column: {
flexDirection: 'column',
},
rowReverse: {
flexDirection: 'row-reverse',
},
columnReverse: {
flexDirection: 'column-reverse',
},
inline: {
display: 'inline-block',
},
whiteVariant: {
backgroundColor: palette.common.white,
},
redVariant: colorVariant(palette.red),
greenVariant: colorVariant(palette.green),
yellowVariant: colorVariant(palette.yellow),
blueVariant: colorVariant(palette.blue),
greyVariant: colorVariant(palette.grey),
...paddings,
...basePaddings,
...margins,
...baseMargins,
...alignItems,
...justifyContent,
...textAlignItems,
...gaps,
...baseGaps,
})

@@ -1,2 +0,3 @@

export { default as getBaseSpacingClasses } from './get-base-spacing-classes'
export { default as filterOutStringAndPicassoSpacing } from './filter-out-strings-and-picasso-spacings'
export * from './get-spacing-classes'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc