Skip to content

Commit

Permalink
Rename tw file to docs-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
cgero-eth committed Oct 11, 2023
1 parent 715a63c commit e7beb76
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/styles/primitives/colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Meta } from '@storybook/blocks';
import { Figma } from '@storybook/addon-designs/blocks';
import classNames from 'classnames';
import { useEffect, useState } from 'react';
import { TailwindUtilities } from '../../utils/tw';
import { docsUtils } from '../../utils';

<Meta title="Design Tokens/Primitive/Colors" />

export const ColorSwatch = ({ colorGroupName }) => {
const [availableColors, setAvailableColors] = useState([]);

useEffect(() => {
const colors = TailwindUtilities.getColorConfig(colorGroupName);
const colors = docsUtils.getColorConfig(colorGroupName);
setAvailableColors(colors);
}, [colorGroupName]);

Expand Down
4 changes: 2 additions & 2 deletions src/styles/primitives/spacing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meta } from '@storybook/blocks';
import { Figma } from '@storybook/addon-designs/blocks';
import classNames from 'classnames';

import { TailwindUtilities } from '../../utils/tw';
import { docsUtils } from '../../utils';

<Meta title="Design Tokens/Primitive/Spacing" />

Expand Down Expand Up @@ -32,7 +32,7 @@ export const DisplayComponent = ({ name, value, sizePx, sizeRem }) => {
</tr>
</thead>
<tbody>
{TailwindUtilities.getSpacingConfig().map(({ key, px, rem, value }) => (
{docsUtils.getSpacingConfig().map(({ key, px, rem, value }) => (
<DisplayComponent key={key} name={key} sizePx={px} sizeRem={rem} value={value} />
))}
</tbody>
Expand Down
10 changes: 6 additions & 4 deletions src/utils/tw.ts → src/utils/docs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import tailwindConfig from '../../tailwind.config';

type Color = { shade: number; value: string };

export class TailwindUtilities {
class DocsUtils {
/**
* Retrieves and processes spacing values from the provided Tailwind CSS configuration.
* The function computes the pixel (px) and relative (rem) sizes based on the given configuration.
* It then returns a sorted list of these computed values.
*/
public static getSpacingConfig() {
getSpacingConfig() {
return Object.entries(resolveConfig(tailwindConfig).theme?.spacing ?? {})
.map(([key, value]) => {
const parsedKey = parseFloat(key);
Expand All @@ -28,7 +28,7 @@ export class TailwindUtilities {
* @param {number} [baseSize=16] - The base size for conversion.
* @returns {number} - The converted value in rem units.
*/
public static pxToRem(px: number, baseSize = 16) {
pxToRem(px: number, baseSize = 16) {
return px / baseSize;
}

Expand All @@ -38,7 +38,7 @@ export class TailwindUtilities {
* @param {string} colorGroupName - Name of the color group.
* @returns {Color[]} Array of available colors.
*/
public static getColorConfig(colorGroupName: string): Color[] {
getColorConfig(colorGroupName: string): Color[] {
const shades = [0, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
const rootStyles = getComputedStyle(document.documentElement);

Expand All @@ -47,3 +47,5 @@ export class TailwindUtilities {
.filter((shade) => shade.value.trim() !== '');
}
}

export const docsUtils = new DocsUtils();
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './docs-utils';
export * from './responsive-utils';
export * from './tw';

0 comments on commit e7beb76

Please sign in to comment.