From a0ad2d1bd2a386794a07414bfa5a6ab21b5ba8fe Mon Sep 17 00:00:00 2001 From: Tsion Behailu Date: Mon, 22 Jan 2024 16:34:43 -0500 Subject: [PATCH 1/4] feat: allow overriding the selectedTab on Tabs component (#186) * allow overriding the selectedTab on Tabs component * useControlledState * remove unused import * add onChange callback --- src/tabs/Tabs.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/tabs/Tabs.tsx b/src/tabs/Tabs.tsx index d302deb6..575fbbcb 100644 --- a/src/tabs/Tabs.tsx +++ b/src/tabs/Tabs.tsx @@ -1,5 +1,4 @@ import React, { - useState, Children, cloneElement, ReactNode, @@ -7,6 +6,7 @@ import React, { ReactElement, HtmlHTMLAttributes, } from 'react'; +import { useControlledState } from '@react-stately/utils'; import { Text } from '../content'; import { css } from '@emotion/react'; import { Orientation } from '../types/orientation'; @@ -112,6 +112,10 @@ function parseTabList(children: ReactNode): Tab[] { export type TabsProps = { children: ReactNode[]; className?: string; + /** + * If specified, the index of the selected tab is controlled by the parent component rather than the internal state. + */ + index?: number; onChange?: (index: number) => void; /** * The orientation of the tabs. Defaults to horizontal @@ -127,6 +131,7 @@ export type TabsProps = { export function Tabs({ children, className, + index, onChange, orientation = 'horizontal', extra, @@ -134,9 +139,13 @@ export function Tabs({ // Filter out the nulls from the children so that tabs can be mounted conditionally children = Children.toArray(children).filter(child => child); const tabs = parseTabList(children); - // Initialize the selected tab to the first non-hidden tab - const [selectedIndex, setSelectedIndex] = useState( - tabs.findIndex(tab => !tab.hidden) + + // Initialize the selected tab to the first non-hidden tab if there is no controlled value provided + const defaultValue = tabs.findIndex(tab => !tab.hidden); + const [selectedIndex, setSelectedIndex] = useControlledState( + index, + defaultValue, + onChange ); return (
{ e.preventDefault(); setSelectedIndex(index); - onChange && onChange(index); }} {...tab?.tabListItemProps} > From fd06d89bdedf2a35c99d75980c29cff11940e37b Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Mon, 22 Jan 2024 15:06:18 -0700 Subject: [PATCH 2/4] v1.0.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b24c520d..f01a1b69 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.0.7", + "version": "1.0.8", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", From e26fda622ebd7f63faf9da89b140f7478175de5e Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Mon, 22 Jan 2024 21:39:52 -0700 Subject: [PATCH 3/4] ci: add release please (#188) * ci: add release please * release please yaml --- .github/workflows/release-package.yml | 4 ++-- .github/workflows/release-please.yaml | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release-please.yaml diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml index a8f59956..c0454e5b 100644 --- a/.github/workflows/release-package.yml +++ b/.github/workflows/release-package.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 12 + node-version: 20 - run: npm ci - run: npm test @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 12 + node-version: 20 registry-url: https://npm.pkg.github.com/ - run: npm ci - run: npm publish diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml new file mode 100644 index 00000000..66b810c5 --- /dev/null +++ b/.github/workflows/release-please.yaml @@ -0,0 +1,24 @@ +on: + push: + branches: + - main + + permissions: + contents: write + pull-requests: write + + name: release-please + + jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v4 + with: + # this assumes that you have created a personal access token + # (PAT) and configured it as a GitHub action secret named + # `MY_RELEASE_PLEASE_TOKEN` (this secret name is not important). + token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + # this is a built-in strategy in release-please, see "Action Inputs" + # for more options + release-type: node \ No newline at end of file From 9b59376e9d993d6745a87058b9c82dbd92b18751 Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Mon, 22 Jan 2024 21:45:22 -0700 Subject: [PATCH 4/4] ci: fix release-please --- .github/workflows/release-please.yaml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml index 66b810c5..6bd8f1ef 100644 --- a/.github/workflows/release-please.yaml +++ b/.github/workflows/release-please.yaml @@ -1,15 +1,14 @@ +name: release-please + on: push: - branches: - - main - - permissions: + branches: [main] + +permissions: contents: write pull-requests: write - - name: release-please - - jobs: + +jobs: release-please: runs-on: ubuntu-latest steps: @@ -17,8 +16,8 @@ on: with: # this assumes that you have created a personal access token # (PAT) and configured it as a GitHub action secret named - # `MY_RELEASE_PLEASE_TOKEN` (this secret name is not important). - token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }} + # `RELEASE_PLEASE_TOKEN` (this secret name is not important). + token: ${{ secrets.RELEASE_PLEASE_TOKEN }} # this is a built-in strategy in release-please, see "Action Inputs" # for more options release-type: node \ No newline at end of file