From 2b5559815ba96ab6e3e25e5418ecd639f7fb485e Mon Sep 17 00:00:00 2001 From: Stuart Hendren Date: Sat, 18 Nov 2023 11:14:51 +0000 Subject: [PATCH] Fixes issue with ThemeProvider and Badge Corrects login in ThemeProvider to stop incorrect removal of theme class Simplifies the typing in Badge, it was correct but ts caused errors, so simplified. --- .changeset/seven-doors-taste.md | 5 +++++ .github/workflows/ci.yml | 5 +---- package.json | 3 ++- packages/ds/package.json | 4 ++-- packages/ds/src/components/Badge/Badge.tsx | 11 ++++++----- .../src/components/ThemeProvider/ThemeProvider.tsx | 12 +++++++----- 6 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 .changeset/seven-doors-taste.md diff --git a/.changeset/seven-doors-taste.md b/.changeset/seven-doors-taste.md new file mode 100644 index 00000000..b0ee65b7 --- /dev/null +++ b/.changeset/seven-doors-taste.md @@ -0,0 +1,5 @@ +--- +'@committed/ds': patch +--- + +Fix to ThemeProvider logic and Badge typeing diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44770947..ed1c664d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,10 +41,6 @@ jobs: - name: Run build run: | pnpm run ci - - name: Config npm - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: create and publish versions uses: changesets/action@v1 if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' @@ -55,3 +51,4 @@ jobs: publish: pnpm ci:publish env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 7bf57f19..bf5bb06f 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,12 @@ "test": "turbo run test", "format": "prettier --write '**/{*.js,*.ts,*.tsx,*.json,*.md,*.mdx}'", "format:check": "prettier -c '**/{*.js,*.ts,*.tsx,*.json,*.md,*.mdx}'", + "changeset": "changeset", "ci:1": "turbo run format:check build", "ci:2": "turbo run lint test", "ci": "pnpm run ci:1 && pnpm install && pnpm ci:2", "ci:publish": "pnpm run ci:packages && pnpm run ci:storybook", - "ci:packages": "pnpm --filter=\"./presets/**\" --filter=\"./packages/**\" publish -r --publish-branch beta --access public --no-git-checks", + "ci:packages": "pnpm --filter=\"./presets/**\" --filter=\"./packages/**\" publish -r --publish-branch beta --access public", "ci:storybook": "pnpm --filter @committed/ds-storybook run deploy-storybook --ci", "ci:version": "pnpm changeset version" }, diff --git a/packages/ds/package.json b/packages/ds/package.json index 1643b50f..66e7c654 100644 --- a/packages/ds/package.json +++ b/packages/ds/package.json @@ -2,8 +2,8 @@ "name": "@committed/ds", "version": "1.0.0", "type": "module", - "main": "src/index.ts", - "types": "src/index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "exports": { ".": { "types": "./dist/index.d.ts", diff --git a/packages/ds/src/components/Badge/Badge.tsx b/packages/ds/src/components/Badge/Badge.tsx index b3123f0d..781f74cb 100644 --- a/packages/ds/src/components/Badge/Badge.tsx +++ b/packages/ds/src/components/Badge/Badge.tsx @@ -1,6 +1,6 @@ import { RecipeVariantProps, cva, styled } from '@committed/ds-ss' import React, { ComponentProps } from 'react' -import { Assign, Prettify, forwardRefDefine } from '../../utils' +import { Prettify, forwardRefDefine } from '../../utils' const DEFAULT_TAG = 'span' @@ -88,14 +88,15 @@ const badge = cva({ const StyledBadge = styled(DEFAULT_TAG, badge) -type BadgeVariants = Omit, 'status'> +type BadgeVariants = RecipeVariantProps type BadgeProps = Prettify< - Assign< - ComponentProps, + Omit< BadgeVariants & { + children: React.ReactNode content: React.ReactNode max?: number - } + }, + 'status' > > diff --git a/packages/ds/src/components/ThemeProvider/ThemeProvider.tsx b/packages/ds/src/components/ThemeProvider/ThemeProvider.tsx index 9c3ba4b0..7a8e35bc 100644 --- a/packages/ds/src/components/ThemeProvider/ThemeProvider.tsx +++ b/packages/ds/src/components/ThemeProvider/ThemeProvider.tsx @@ -72,11 +72,13 @@ const ControlledThemeProvider: FC = ({ ) } else { const prevTheme = prevThemeRef.current - if (prevTheme) { - document.body.classList.remove(prevTheme) - } - if (theme) { - document.body.classList.add(theme) + if (prevTheme !== theme) { + if (prevTheme) { + document.body.classList.remove(prevTheme) + } + if (theme) { + document.body.classList.add(theme) + } } return <>{children} }