Skip to content

Commit

Permalink
feat: moving private components to ui-private
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini committed Feb 26, 2024
1 parent 1f7ecd2 commit 52c8939
Show file tree
Hide file tree
Showing 87 changed files with 635 additions and 160 deletions.
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"packages/eslint-plugin-client": "1.0.1",
"packages/ui-components": "5.1.0",
"packages/ui-hooks": "2.2.0",
"packages/ui-system": "1.0.0"
"packages/ui-system": "1.0.0",
"packages/ui-private": "0.0.0"
}
3 changes: 2 additions & 1 deletion packages/ui-components/lib/buildIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const iconTemplate = ({
*
*/
import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";
import type { IconsProps } from "./IconsTypes";
export const ${name} = ({
Expand Down
11 changes: 4 additions & 7 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,17 @@
"test": "vitest run"
},
"peerDependencies": {
"@floating-ui/react": "0.26.9",
"fast-equals": "5.0.1",
"micro-memoize": "4.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"react": "18.2.0",
"react-dom": "18.2.0"
},
"dependencies": {
"@floating-ui/react": "0.26.9",
"@tailwindcss/typography": "0.5.10",
"@versini/ui-hooks": ">=2.1.1",
"@versini/ui-private": "workspace:../ui-private",
"clsx": "2.1.0",
"fast-equals": "5.0.1",
"micro-memoize": "4.1.2",
"tailwindcss": "3.4.1"
},
"sideEffects": [
Expand Down
20 changes: 1 addition & 19 deletions packages/ui-components/src/common/__tests__/utilities.test.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
import { describe, expect, it } from "vitest";

import { getSpacing, isEmpty, truncate } from "../utilities";
import { isEmpty, truncate } from "../utilities";

describe("Non-DOM tests", () => {
describe("getSpacing", () => {
it("should return the correct spacing class", () => {
expect(getSpacing(123)).toBe("m-123");
expect(getSpacing("123")).toBe("m-123");

expect(getSpacing({ t: 123 })).toBe("mt-123");
expect(getSpacing({ r: 123 })).toBe("mr-123");
expect(getSpacing({ b: 123 })).toBe("mb-123");
expect(getSpacing({ l: 123 })).toBe("ml-123");
expect(getSpacing({ t: 123, r: 456 })).toBe("mt-123 mr-456");
expect(getSpacing({ t: 123, b: 456 })).toBe("mt-123 mb-456");
expect(getSpacing({ t: 123, l: 456 })).toBe("mt-123 ml-456");
expect(getSpacing({ r: 123, b: 456 })).toBe("mr-123 mb-456");
expect(getSpacing({ r: 123, l: 456 })).toBe("mr-123 ml-456");
expect(getSpacing({ b: 123, l: 456 })).toBe("mb-123 ml-456");
});
});

describe("truncate", () => {
it("should truncate according to plan", () => {
const STR = "hello world";
Expand Down
65 changes: 0 additions & 65 deletions packages/ui-components/src/common/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
import { deepEqual } from "fast-equals";
import memoize from "micro-memoize";

import type { SpacingType } from ".";

const hasOwnProperty = Object.prototype.hasOwnProperty;
const toString = Object.prototype.toString;
const objectProto = Object.prototype;

export const isProd = process.env.NODE_ENV === "production";
export const isDev = !isProd;

/**
* Memoize function calls with arguments that are
* complex objects (hence "deep"). Do not use for
* standard types.
* @param {Function} fct - the function to optimize.
* @returns the optimized function.
*/
export function memoizeDeep(fct: any) {
return memoize(fct, { isEqual: deepEqual });
}

/**
* Checks if `value` is a valid array-like length.
*/
Expand Down Expand Up @@ -93,52 +77,3 @@ export const truncate = (fullString: string, maxLength: number) => {
fullString,
};
};

/**
* This method returns a string that can be used as a tailwind class relying
* on margins definitions (m, mt, mb, etc.).
* Please refer to: https://tailwindcss.com/docs/margin
*
* It accepts a number, a string or an object.
* If a number is passed, it will be converted to a string and prefixed with "m-".
* If a string is passed, it will be prefixed with "m-".
* If an object is passed, it will be converted to a string like this:
* { t: 4, r: 1, b: 3, l: 5} => "mt-4 mr-1 mb-3 ml-5"
*
*/
export const getSpacing = memoizeDeep((spacing: SpacingType): string => {
let spacingClass = "";
/**
* In this case, spacing is a number or a string. For example:
* spacing = 4
* which will be converted to:
* "m-4"
*/
if (typeof spacing === "number" || typeof spacing === "string") {
spacingClass = "m-" + spacing;
} else {
/**
* in this case spacing is an object like this:
* spacing = { t: 4, r: 1, b: 3, l: 5}
* All keys are optional.
* The following lines will transform this object into a string like this:
* "mt-4 mr-1 mb-3 ml-5"
*/
const classes = [];
if (spacing?.t !== undefined) {
classes.push(`mt-${spacing.t}`);
}
if (spacing?.r !== undefined) {
classes.push(`mr-${spacing.r}`);
}
if (spacing?.b !== undefined) {
classes.push(`mb-${spacing.b}`);
}
if (spacing?.l !== undefined) {
classes.push(`ml-${spacing.l}`);
}
spacingClass = classes.join(" ");
}

return spacingClass;
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpacingProps } from "../../common";
import type { SpacingProps } from "@versini/ui-private/dist/utilities";

export type BubbleProps = {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/src/components/Bubble/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SpacingProps } from "@versini/ui-private/dist/utilities";
import { getSpacing } from "@versini/ui-private/dist/utilities";
import clsx from "clsx";

import type { SpacingProps } from "../../common";
import { BUBBLE_CLASSNAME } from "../../common/constants";
import { getSpacing } from "../../common/utilities";

const getBubbleSizesClasses = () => {
return "p-4 sm:max-w-md md:max-w-2xl";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpacingProps } from "../../common";
import type { SpacingProps } from "@versini/ui-private/dist/utilities";

export type CommonButtonProps = {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/src/components/Button/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SpacingProps } from "@versini/ui-private/dist/utilities";
import { getSpacing } from "@versini/ui-private/dist/utilities";
import clsx from "clsx";

import type { SpacingProps } from "../../common";
import { BUTTON_CLASSNAME } from "../../common/constants";
import { getSpacing } from "../../common/utilities";

export const TYPE_ICON = "icon";
export const TYPE_BUTTON = "button";
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-components/src/components/Card/CardTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpacingProps } from "../../common";
import type { SpacingProps } from "@versini/ui-private/dist/utilities";

export type CardProps = {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/src/components/Card/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SpacingProps } from "@versini/ui-private/dist/utilities";
import { getSpacing } from "@versini/ui-private/dist/utilities";
import clsx from "clsx";

import type { SpacingProps } from "../../common";
import { CARD_CLASSNAME } from "../../common/constants";
import { getSpacing } from "../../common/utilities";

type getCardClassesProps = {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-components/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getSpacing } from "@versini/ui-private/dist/utilities";
import clsx from "clsx";

import { FOOTER_CLASSNAME } from "../../common/constants";
import { getSpacing } from "../../common/utilities";
import type { FooterProps } from "./FooterTypes";

export const Footer = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpacingProps } from "../../common";
import type { SpacingProps } from "@versini/ui-private/dist/utilities";

export type FooterProps = {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-components/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getSpacing } from "@versini/ui-private/dist/utilities";
import clsx from "clsx";

import { HEADER_CLASSNAME } from "../../common/constants";
import { getSpacing } from "../../common/utilities";
import { HeaderProps } from "./HeaderTypes";

export const Header = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpacingProps } from "../../common";
import type { SpacingProps } from "@versini/ui-private/dist/utilities";

export type HeaderProps = {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconBack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconBack = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconChart = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconClose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconClose = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconCopied.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconCopied = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconCopy = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconDelete = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconDog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconDog = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconEdit = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconGitHub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconGitHub = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconHide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconHide = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconHistory = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconInfo = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconNext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconNext = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconPrevious.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconPrevious = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconProfile = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconRestore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconRestore = ({
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-components/src/components/Icons/IconSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*
*/

import { SvgIcon } from "../private/SvgIcon/SvgIcon";
import { SvgIcon } from "@versini/ui-private";

import type { IconsProps } from "./IconsTypes";

export const IconSettings = ({
Expand Down
Loading

0 comments on commit 52c8939

Please sign in to comment.