Skip to content

[pull] main from coreui:main #4

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

Merged
merged 4 commits into from
May 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

Several quick start options are available:

- [Download the latest release](https://github.com/coreui/coreui-react/archive/v5.0.0.zip)
- [Download the latest release](https://github.com/coreui/coreui-react/archive/v5.1.0.zip)
- Clone the repo: `git clone https://github.com/coreui/coreui-react.git`
- Install with [npm](https://www.npmjs.com/): `npm install @coreui/react`
- Install with [yarn](https://yarnpkg.com/): `yarn add @coreui/react`
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"npmClient": "yarn",
"packages": ["packages/*"],
"version": "5.0.0",
"version": "5.1.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion packages/coreui-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

Several quick start options are available:

- [Download the latest release](https://github.com/coreui/coreui-react/archive/v5.0.0.zip)
- [Download the latest release](https://github.com/coreui/coreui-react/archive/v5.1.0.zip)
- Clone the repo: `git clone https://github.com/coreui/coreui-react.git`
- Install with [npm](https://www.npmjs.com/): `npm install @coreui/react`
- Install with [yarn](https://yarnpkg.com/): `yarn add @coreui/react`
Expand Down
4 changes: 2 additions & 2 deletions packages/coreui-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coreui/react",
"version": "5.0.0",
"version": "5.1.0",
"description": "UI Components Library for React.js",
"keywords": [
"react",
Expand Down Expand Up @@ -41,7 +41,7 @@
"test:update": "jest --coverage --updateSnapshot"
},
"dependencies": {
"@coreui/coreui": "^5.0.1",
"@coreui/coreui": "^5.0.2",
"@popperjs/core": "^2.11.8",
"prop-types": "^15.8.1"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/coreui-react/src/components/tabs/CTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export interface CTabProps extends HTMLAttributes<HTMLButtonElement> {
/**
* Item key.
*/
itemKey?: number | string
itemKey: number | string
}

export const CTab = forwardRef<HTMLButtonElement, CTabProps>(
({ children, className, itemKey, ...rest }, ref) => {
const { _activeItemKey, setActiveKey, id } = useContext(TabsContext)
const { _activeItemKey, setActiveItemKey, id } = useContext(TabsContext)

const isActive = () => itemKey === _activeItemKey

Expand All @@ -31,8 +31,8 @@ export const CTab = forwardRef<HTMLButtonElement, CTabProps>(
className,
)}
id={`${id}${itemKey}-tab`}
onClick={() => setActiveKey(itemKey)}
onFocus={() => setActiveKey(itemKey)}
onClick={() => setActiveItemKey(itemKey)}
onFocus={() => setActiveItemKey(itemKey)}
role="tab"
tabIndex={isActive() ? 0 : -1}
type="button"
Expand All @@ -50,7 +50,7 @@ export const CTab = forwardRef<HTMLButtonElement, CTabProps>(
CTab.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
itemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
itemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}

CTab.displayName = 'CTab'
8 changes: 4 additions & 4 deletions packages/coreui-react/src/components/tabs/CTabList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export interface CTabListProps extends HTMLAttributes<HTMLDivElement> {

export const CTabList = forwardRef<HTMLDivElement, CTabListProps>(
({ children, className, layout, variant, ...rest }, ref) => {
const tabsRef = useRef<HTMLDivElement | HTMLUListElement | HTMLOListElement>(null)
const forkedRef = useForkedRef(ref, tabsRef)
const tabListRef = useRef<HTMLDivElement>(null)
const forkedRef = useForkedRef(ref, tabListRef)

const handleKeydown = (event: KeyboardEvent<HTMLDivElement>) => {
if (
tabsRef.current !== null &&
tabListRef.current !== null &&
(event.key === 'ArrowDown' ||
event.key === 'ArrowUp' ||
event.key === 'ArrowLeft' ||
Expand All @@ -39,7 +39,7 @@ export const CTabList = forwardRef<HTMLDivElement, CTabListProps>(
const target = event.target as HTMLElement
// eslint-disable-next-line unicorn/prefer-spread
const items: HTMLElement[] = Array.from(
tabsRef.current.querySelectorAll('.nav-link:not(.disabled):not(:disabled)'),
tabListRef.current.querySelectorAll('.nav-link:not(.disabled):not(:disabled)'),
)

let nextActiveElement
Expand Down
4 changes: 2 additions & 2 deletions packages/coreui-react/src/components/tabs/CTabPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface CTabPanelProps extends HTMLAttributes<HTMLDivElement> {
/**
* Item key.
*/
itemKey?: number | string
itemKey: number | string
/**
* Callback fired when the component requests to be hidden.
*/
Expand Down Expand Up @@ -88,7 +88,7 @@ export const CTabPanel = forwardRef<HTMLDivElement, CTabPanelProps>(
CTabPanel.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
itemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
itemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
onHide: PropTypes.func,
onShow: PropTypes.func,
transition: PropTypes.bool,
Expand Down
10 changes: 5 additions & 5 deletions packages/coreui-react/src/components/tabs/CTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface CTabsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChan
/**
* The active item key.
*/
activeItemKey?: number | string
activeItemKey: number | string
/**
* A string of all className you want applied to the base component.
*/
Expand All @@ -19,7 +19,7 @@ export interface CTabsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChan

export interface TabsContextProps {
_activeItemKey?: number | string
setActiveKey: React.Dispatch<React.SetStateAction<number | string | undefined>>
setActiveItemKey: React.Dispatch<React.SetStateAction<number | string | undefined>>
id?: string
}

Expand All @@ -28,14 +28,14 @@ export const TabsContext = createContext({} as TabsContextProps)
export const CTabs = forwardRef<HTMLDivElement, CTabsProps>(
({ children, activeItemKey, className, onChange }, ref) => {
const id = useId()
const [_activeItemKey, setActiveKey] = useState(activeItemKey)
const [_activeItemKey, setActiveItemKey] = useState(activeItemKey)

useEffect(() => {
_activeItemKey && onChange && onChange(_activeItemKey)
}, [_activeItemKey])

return (
<TabsContext.Provider value={{ _activeItemKey, setActiveKey, id }}>
<TabsContext.Provider value={{ _activeItemKey, setActiveItemKey, id }}>
<div className={classNames('tabs', className)} ref={ref}>
{children}
</div>
Expand All @@ -45,7 +45,7 @@ export const CTabs = forwardRef<HTMLDivElement, CTabsProps>(
)

CTabs.propTypes = {
activeItemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
activeItemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
children: PropTypes.node,
className: PropTypes.string,
onChange: PropTypes.func,
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coreui/react-docs",
"version": "5.0.0",
"version": "5.1.0",
"private": true,
"description": "",
"homepage": "https://coreui.io/react/",
Expand All @@ -25,7 +25,7 @@
},
"dependencies": {
"@coreui/chartjs": "^4.0.0",
"@coreui/coreui": "^5.0.1",
"@coreui/coreui": "^5.0.2",
"@coreui/icons": "^3.0.1",
"@coreui/icons-react": "^2.2.1",
"@coreui/react-chartjs": "^3.0.0",
Expand Down
20 changes: 17 additions & 3 deletions packages/docs/src/styles/_component-examples.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@
// Docs examples
//

.tab-content .tab-pane {
@include border-top-radius(0);
.docs-code-tabs {
padding: 0 ($cd-gutter-x * .5);
margin: 0 ($cd-gutter-x * -.5);

.highlight {
@include media-breakpoint-up(md) {
padding: 0;
margin: 0;
}
}

.docs-code-tab-content {
.tab-pane > .docs-code-snippet,
.tab-pane > .highlight {
border-top: 0;
@include border-top-radius(0);

.highlight {
@include border-top-radius(0);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/remark-code-tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function createTabs(tabNodes, { labels }) {
children: [
{
attributes: [
{ name: 'className', type: 'mdxJsxAttribute', value: 'docs-code-tabs' },
{
name: 'variant',
type: 'mdxJsxAttribute',
Expand All @@ -155,7 +156,9 @@ function createTabs(tabNodes, { labels }) {
type: 'mdxJsxFlowElement',
},
{
attributes: [{ name: 'className', type: 'mdxJsxAttribute', value: 'mb-3' }],
attributes: [
{ name: 'className', type: 'mdxJsxAttribute', value: 'docs-code-tab-content mb-3' },
],
children: tabContentChildren,
name: 'CTabContent',
type: 'mdxJsxFlowElement',
Expand Down