Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shared): Add trim to mergeClasses #2522

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/lucide-preact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- packages/lucide-preact/**
- packages/shared/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- packages/lucide-react-native/**
- packages/shared/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- packages/lucide-react/**
- packages/shared/**
- tools/build-icons/**
- tools/rollup-plugins/**
- scripts/generateNextJSAliases.mjs
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/lucide-shared.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lucide Shared Checks

on:
pull_request:
paths:
- packages/shared/**
- pnpm-lock.yaml

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/[email protected]
with:
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Test
run: pnpm --filter lucide-react test
1 change: 1 addition & 0 deletions .github/workflows/lucide-solid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- packages/lucide-solid/**
- packages/shared/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-svelte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- packages/lucide-svelte/**
- packages/shared/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-vue-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- packages/lucide-vue-next/**
- packages/shared/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lucide-vue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- packages/lucide-vue/**
- packages/shared/**
- tools/build-icons/**
- tools/rollup-plugins/**
- pnpm-lock.yaml
Expand Down
9 changes: 7 additions & 2 deletions packages/shared/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const toPascalCase = <T extends string>(string: T): CamelToPascal<T> => {
export const mergeClasses = <ClassType = string | undefined | null>(...classes: ClassType[]) =>
classes
.filter((className, index, array) => {
return Boolean(className) && array.indexOf(className) === index;
return (
Boolean(className) &&
(className as string).trim() !== '' &&
array.indexOf(className) === index
);
})
.join(' ');
.join(' ')
.trim();
8 changes: 8 additions & 0 deletions packages/shared/tests/utils.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ describe('mergeClasses', () => {
const classes = mergeClasses('lucide', 'lucide-circle', 'lucide');
expect(classes).toBe('lucide lucide-circle');
});
it('trims the string', async () => {
const classes = mergeClasses('lucide', 'lucide-circle', ' ');
expect(classes).toBe('lucide lucide-circle');
});
it('trims the sub strings', async () => {
const classes = mergeClasses('lucide', ' ', 'lucide-circle');
expect(classes).toBe('lucide lucide-circle');
});
});
Loading