Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
87528a3
refactor(theme): replace lodash code
wingkwong Jun 24, 2024
9c06485
refactor(deps): remove lodash packages
wingkwong Jun 24, 2024
30a967f
refactor(theme): replace lodash get usage
wingkwong Jun 24, 2024
16560e7
refactor(use-infinite-scroll): replace lodash debounce
wingkwong Jun 24, 2024
74d431e
refactor(calendar): replace lodash debounce
wingkwong Jun 24, 2024
79bd8ce
refactor(docs): replace lodash captialize function
wingkwong Jun 24, 2024
84eaa29
refactor(docs): replace lodash isEmpty
wingkwong Jun 24, 2024
f17abf7
feat(shared-utils): add isEmpty function
wingkwong Jun 24, 2024
e795c09
refactor(docs): replace lodash toLower
wingkwong Jun 24, 2024
dd0b4fd
refactor(docs): replace lodash get
wingkwong Jun 24, 2024
0bcbf50
refactor(docs): replace lodash includes
wingkwong Jun 24, 2024
7631c00
refactor(docs): replace lodash capitalize & last
wingkwong Jun 24, 2024
3cd96a0
refactor(docs): replace lodash clamp & get
wingkwong Jun 24, 2024
5efa8fe
feat(shared-utils): add clamp
wingkwong Jun 24, 2024
041e626
refactor(docs): replace lodash intersectionBy
wingkwong Jun 24, 2024
4ac3a72
refactor(docs): replace lodash get
wingkwong Jun 24, 2024
850bf00
refactor(docs): replace lodash debounce
wingkwong Jun 24, 2024
7ec3f31
refactor(shared-utils): add debounce
wingkwong Jun 24, 2024
b047210
refactor(calendar): use debounce from shared-utils
wingkwong Jun 24, 2024
de13826
refactor(docs): replace lodash uniqBy
wingkwong Jun 24, 2024
baae196
feat(shared-utils): add uniqBy
wingkwong Jun 24, 2024
f5e2d19
refactor(docs): replace lodash get
wingkwong Jun 24, 2024
b1df0b9
chore(deps): remove lodash dependencies
wingkwong Jun 24, 2024
febed4d
fix(docs): add back lowerTitle
wingkwong Jun 24, 2024
5efe60d
chore(deps): include @nextui-org/shared-utils
wingkwong Jun 24, 2024
c0f22a4
chore(theme): move kebabCase to shared-utils and use omit
wingkwong Jun 24, 2024
25a33a8
fix(docs): add missing omit import
wingkwong Jun 24, 2024
a827498
chore(deps): pnpm-lock.yaml
wingkwong Jun 24, 2024
522596e
chore(deps): keep lodash for intersectionBy
wingkwong Jun 24, 2024
93996d9
refactor(docs): tree shake intersectionBy
wingkwong Jun 24, 2024
c54c9c8
feat(shared-utils): add omit and kebabCase
wingkwong Jun 24, 2024
6934dd3
refactor(shared-utils): remove isEmpty and clamp
wingkwong Jun 25, 2024
50eae3d
feat(changeset): add changeset
wingkwong Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/warm-suits-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@nextui-org/calendar": patch
"@nextui-org/theme": patch
"@nextui-org/use-infinite-scroll": patch
"@nextui-org/shared-utils": patch
---

replaced lodash with native approaches
2 changes: 1 addition & 1 deletion apps/docs/app/examples/table/custom-styles/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "@nextui-org/react";
import {ChevronDownIcon, SearchIcon} from "@nextui-org/shared-icons";
import {useCallback, useMemo, useState} from "react";
import {capitalize} from "lodash";
import {capitalize} from "@nextui-org/shared-utils";

import {PlusLinearIcon} from "@/components/icons";
import {VerticalDotsIcon} from "@/components/icons/vertical-dots";
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/app/examples/table/use-case/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "@nextui-org/react";
import {ChevronDownIcon, SearchIcon} from "@nextui-org/shared-icons";
import {useCallback, useMemo, useState} from "react";
import {capitalize} from "lodash";
import {capitalize} from "@nextui-org/shared-utils";

import {PlusLinearIcon} from "@/components/icons";
import {VerticalDotsIcon} from "@/components/icons/vertical-dots";
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/components/cmdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {clsx} from "@nextui-org/shared-utils";
import scrollIntoView from "scroll-into-view-if-needed";
import {isAppleDevice, isWebKit} from "@react-aria/utils";
import {create} from "zustand";
import {intersectionBy, isEmpty} from "lodash";
import {isEmpty} from "@nextui-org/shared-utils";
import intersectionBy from "lodash/intersectionBy";
import {writeStorage, useLocalStorage} from "@rehooks/local-storage";

import {
Expand Down
5 changes: 2 additions & 3 deletions apps/docs/components/demo-code-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Skeleton,
} from "@nextui-org/react";
import Link from "next/link";
import {toLower} from "lodash";

import {CodeWindow} from "@/components/code-window";
import {useIsMobile} from "@/hooks/use-media-query";
Expand All @@ -30,8 +29,8 @@ export const DemoCodeModal: FC<DemoCodeModalProps> = ({isOpen, code, title, subt

const isMobile = useIsMobile();

const lowerTitle = toLower(title);
const fileName = `${toLower(lowerTitle)}.tsx`;
const lowerTitle = title.toLowerCase();
const fileName = `${lowerTitle}.tsx`;

return (
<Modal
Expand Down
10 changes: 6 additions & 4 deletions apps/docs/components/docs/components/code-demo/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import {get} from "lodash";

import {FileCode} from "./types";

const importRegex = /^(import)\s(?!type(of\s|\s)(?!from)).*?$/gm;

const exportDefaultRegex = /export\s+default\s+function\s+\w+\s*\(\s*\)\s*\{/;

export const transformCode = (code: string, imports = {}, compName = "App") => {
export const transformCode = (
code: string,
imports: {[key: string]: any} = {},
compName = "App",
) => {
let cleanedCode = code
.replace(importRegex, (match) => {
// get component name from the match ex. "import { Table } from '@nextui-org/react'"
const componentName = match.match(/\w+/g)?.[1] || "";
const matchingImport = get(imports, componentName);
const matchingImport = imports[componentName] || {};

if (matchingImport) {
// remove the matching import
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/components/docs/components/codeblock.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {forwardRef, useEffect} from "react";
import {clsx, dataAttr, getUniqueID} from "@nextui-org/shared-utils";
import BaseHighlight, {Language, PrismTheme, defaultProps} from "prism-react-renderer";
import {debounce, omit} from "lodash";
import {debounce, omit} from "@nextui-org/shared-utils";

import defaultTheme from "@/libs/prism-theme";

Expand Down
10 changes: 5 additions & 5 deletions apps/docs/components/docs/components/swatch-colors-set.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {parseToRgba, readableColor} from "color2k";
import {Button, Tooltip} from "@nextui-org/react";
import {commonColors, semanticColors} from "@nextui-org/theme";
import {commonColors, semanticColors, SemanticBaseColors, ThemeColors} from "@nextui-org/theme";
import {useClipboard} from "@nextui-org/use-clipboard";
import {useState} from "react";
import {useTheme} from "next-themes";
import {get, isEmpty} from "lodash";
import {isEmpty} from "@nextui-org/shared-utils";

type ColorsItem = {
color: string;
Expand Down Expand Up @@ -106,12 +106,12 @@ const SemanticSwatch = ({
let value: string = "";
const [colorName, colorScale] = color.split("-");

let currentPalette = get(semanticColors, theme ?? "", {});
const currentPalette = semanticColors[theme as keyof SemanticBaseColors] || {};

if (!colorScale) {
value = get(currentPalette, `${colorName}.DEFAULT`, "");
value = (currentPalette[colorName as keyof ThemeColors] as any)?.DEFAULT || "";
} else {
value = get(currentPalette, `${colorName}.${colorScale}`, "");
value = (currentPalette[colorName as keyof ThemeColors] as any)?.colorScale || "";
}

const handleCopy = () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/components/docs/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
dataFocusVisibleClasses,
} from "@nextui-org/react";
import Link from "next/link";
import {isEmpty} from "lodash";
import {isEmpty} from "@nextui-org/shared-utils";
import {usePathname, useRouter} from "next/navigation";

import {ScrollArea} from "../scroll-area";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* eslint-disable react/display-name */
import {useMemo, useState} from "react";
import {Tabs, Tab, Card, CardBody, Image, Button, RadioGroup, Radio} from "@nextui-org/react";
import get from "lodash/get";
import NextLink from "next/link";
import NextImage from "next/image";

Expand Down Expand Up @@ -238,7 +237,7 @@ export const CustomThemes = () => {
<CodeWindow
showWindowIcons
className="max-h-[440px] min-h-[390px]"
highlightLines={get(codeHighlights, selectedTheme)}
highlightLines={codeHighlights[selectedTheme]}
isScrollable={false}
language="jsx"
title="tailwind.config.js"
Expand Down
6 changes: 2 additions & 4 deletions apps/docs/components/marketing/support.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {FC, useMemo, useRef} from "react";
import {Avatar, AvatarProps, Button, Spacer, Tooltip} from "@nextui-org/react";
import {clamp, get} from "lodash";
import {clamp} from "@nextui-org/shared-utils";

import {sectionWrapper, titleWrapper, title, subtitle} from "../primitives";

Expand Down Expand Up @@ -132,9 +132,7 @@ export const Support: FC<SupportProps> = ({sponsors = []}) => {
size={getSponsorSize(sponsor, isMobile)}
src={sponsor.image}
style={getSponsorAvatarStyles(index, sponsors)}
onClick={() =>
handleExternalLinkClick(get(sponsor, "website") || get(sponsor, "profile"))
}
onClick={() => handleExternalLinkClick(sponsor["website"] || sponsor["profile"])}
/>
))}
</div>
Expand Down
9 changes: 4 additions & 5 deletions apps/docs/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {isAppleDevice} from "@react-aria/utils";
import {clsx} from "@nextui-org/shared-utils";
import NextLink from "next/link";
import {usePathname} from "next/navigation";
import {includes} from "lodash";
import {motion, AnimatePresence} from "framer-motion";
import {useEffect} from "react";
import {usePress} from "@react-aria/interactions";
Expand Down Expand Up @@ -197,7 +196,7 @@ export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], sl
<NextLink
className={navLinkClasses}
color="foreground"
data-active={includes(docsPaths, pathname)}
data-active={docsPaths.includes(pathname)}
href="/docs/guide/introduction"
onClick={() => handlePressNavbarItem("Docs", "/docs/guide/introduction")}
>
Expand All @@ -208,7 +207,7 @@ export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], sl
<NextLink
className={navLinkClasses}
color="foreground"
data-active={includes(pathname, "components")}
data-active={pathname.includes("components")}
href="/docs/components/avatar"
onClick={() => handlePressNavbarItem("Components", "/docs/components/avatar")}
>
Expand All @@ -219,7 +218,7 @@ export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], sl
<NextLink
className={navLinkClasses}
color="foreground"
data-active={includes(pathname, "blog")}
data-active={pathname.includes("blog")}
href="/blog"
onClick={() => handlePressNavbarItem("Blog", "/blog")}
>
Expand All @@ -230,7 +229,7 @@ export const Navbar: FC<NavbarProps> = ({children, routes, mobileRoutes = [], sl
<NextLink
className={navLinkClasses}
color="foreground"
data-active={includes(pathname, "figma")}
data-active={pathname.includes("figma")}
href="/figma"
onClick={() => handlePressNavbarItem("Figma", "/figma")}
>
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/components/sandpack/bugreport-button.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from "react";
import {usePathname} from "next/navigation";
import {Tooltip, Button} from "@nextui-org/react";
import {capitalize, last} from "lodash";
import {capitalize} from "@nextui-org/shared-utils";

import {BugIcon} from "@/components/icons";
import {ISSUE_REPORT_URL} from "@/libs/github/constants";

export const BugReportButton = () => {
const pathname = usePathname();

const componentTitle = capitalize(last(pathname?.split("/")));
const componentTitle = capitalize(pathname?.split("/")?.at(-1) ?? "");

const handlePress = () => {
window.open(`${ISSUE_REPORT_URL}${componentTitle}`, "_blank");
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/components/table/custom-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ const users = [

export {columns, users, statusOptions};`;

const utils = `export function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
const utils = `export function capitalize(s) {
return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : "";
}`;

const PlusIcon = `export const PlusIcon = ({size = 24, width, height, ...props}) => (
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/content/components/table/use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ export type IconSvgProps = SVGProps<SVGSVGElement> & {
size?: number;
};`;

const utils = `export function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
const utils = `export function capitalize(s) {
return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : "";
}`;

const PlusIcon = `export const PlusIcon = ({size = 24, width, height, ...props}) => (
Expand Down Expand Up @@ -544,8 +544,8 @@ const ChevronDownIcon = `export const ChevronDownIcon = ({strokeWidth = 1.5, ...
</svg>
);`;

const utilsTs = `export function capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
const utilsTs = `export function capitalize(s: string) {
return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : "";
}`;

const PlusIconTs = `import {IconSvgProps} from "./types";
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"@react-types/shared": "3.23.1",
"@tailwindcss/typography": "^0.5.9",
"@types/canvas-confetti": "^1.4.2",
"@types/lodash": "^4.14.194",
"@types/lodash": "^4.17.5",
"@types/marked": "^5.0.0",
"@types/mdx": "^2.0.5",
"@types/node": "20.2.5",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/utils/get-sponsors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {uniqBy} from "lodash";
import {uniqBy} from "@nextui-org/shared-utils";
import fetch from "node-fetch";

import {__PROD__} from "./env";
Expand Down
4 changes: 1 addition & 3 deletions packages/components/calendar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"@nextui-org/framer-utils": "workspace:*",
"@nextui-org/use-aria-button": "workspace:*",
"@nextui-org/button": "workspace:*",
"lodash.debounce": "^4.0.8",
"@internationalized/date": "^3.5.4",
"@react-aria/calendar": "3.5.8",
"@react-aria/focus": "3.17.1",
Expand All @@ -59,8 +58,7 @@
"@react-types/calendar": "3.4.6",
"@react-aria/interactions": "3.21.3",
"@react-types/shared": "3.23.1",
"scroll-into-view-if-needed": "3.0.10",
"@types/lodash.debounce": "^4.0.7"
"scroll-into-view-if-needed": "3.0.10"
},
"devDependencies": {
"@nextui-org/system": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/calendar/src/use-calendar-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {PressEvent} from "@react-types/shared";
import {useDateFormatter} from "@react-aria/i18n";
import {HTMLNextUIProps} from "@nextui-org/system";
import {useCallback, useRef, useEffect} from "react";
import debounce from "lodash.debounce";
import {areRectsIntersecting} from "@nextui-org/react-utils";
import {debounce} from "@nextui-org/shared-utils";
import scrollIntoView from "scroll-into-view-if-needed";

import {getMonthsInYear, getYearRange} from "./utils";
Expand Down
52 changes: 42 additions & 10 deletions packages/core/theme/__tests__/semantic-colors.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {getContrast} from "color2k";
import get from "lodash.get";

import {semanticColors} from "../src/colors/semantic";

Expand All @@ -8,10 +7,13 @@ type Guideline = keyof typeof guidelines;
const guidelines = {decorative: 1.5, readable: 3, aa: 4.5, aaa: 7};
const targetGuideline: Guideline = "readable";

const testGoodContrast = (colorPath: string, backgroundPath: string, standard: Guideline) => {
const color = get(semanticColors, colorPath);
const background = get(semanticColors, backgroundPath);

const testGoodContrast = (
colorPath: string,
color: string,
backgroundPath: string,
background: string,
standard: Guideline,
) => {
it(`${colorPath}(${color}) has enough contrast with ${backgroundPath}(${background}) to be ${standard}`, () => {
expect(getContrast(color, background)).toBeGreaterThanOrEqual(guidelines[standard]);
});
Expand All @@ -20,14 +22,44 @@ const testGoodContrast = (colorPath: string, backgroundPath: string, standard: G
describe("semanticColors", () => {
["light", "dark"].forEach((mode) => {
describe(mode, () => {
testGoodContrast(`${mode}.divider.DEFAULT`, `${mode}.background.DEFAULT`, "decorative");
testGoodContrast(`${mode}.foreground.DEFAULT`, `${mode}.background.DEFAULT`, targetGuideline);
testGoodContrast(
`${mode}.divider.DEFAULT`,
semanticColors[mode]?.divider?.DEFAULT,
`${mode}.background.DEFAULT`,
semanticColors[mode]?.background?.DEFAULT,
"decorative",
);
testGoodContrast(
`${mode}.foreground.DEFAULT`,
semanticColors[mode]?.foreground?.DEFAULT,
`${mode}.background.DEFAULT`,
semanticColors[mode]?.background?.DEFAULT,
targetGuideline,
);
["default", "content1", "content2", "content3", "content4"].forEach((name) => {
testGoodContrast(`${mode}.foreground.DEFAULT`, `${mode}.${name}.DEFAULT`, targetGuideline);
testGoodContrast(`${mode}.${name}.foreground`, `${mode}.${name}.DEFAULT`, targetGuideline);
testGoodContrast(
`${mode}.foreground.DEFAULT`,
semanticColors[mode]?.foreground?.DEFAULT,
`${mode}.${name}.DEFAULT`,
semanticColors[mode]?.[name]?.DEFAULT,
targetGuideline,
);
testGoodContrast(
`${mode}.${name}.foreground`,
semanticColors[mode]?.[name]?.foreground,
`${mode}.${name}.DEFAULT`,
semanticColors[mode]?.[name]?.DEFAULT,
targetGuideline,
);
});
["primary", "secondary", "success", "warning", "danger"].forEach((name) => {
testGoodContrast(`${mode}.${name}.foreground`, `${mode}.${name}.DEFAULT`, targetGuideline);
testGoodContrast(
`${mode}.${name}.foreground`,
semanticColors[mode]?.[name]?.foreground,
`${mode}.${name}.DEFAULT`,
semanticColors[mode]?.[name]?.DEFAULT,
targetGuideline,
);
});
});
});
Expand Down
Loading