Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(CSidebar): add 'as' prop to CSidebar#421

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mrholek merged 1 commit intocoreui:mainfrommatt-jb:add-as-prop-to-sidebar
Dec 31, 2024
Merged
Changes fromall 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
20 changes: 15 additions & 5 deletionspackages/coreui-react/src/components/sidebar/CSidebar.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, HTMLAttributes, useEffect, useRef, useState } from 'react'
import React, {ElementType,forwardRef, HTMLAttributes, useEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import PropTypes from 'prop-types'
import classNames from 'classnames'
Expand All@@ -7,8 +7,13 @@ import { CBackdrop } from '../backdrop'

import { isInViewport } from '../../utils'
import { useForkedRef } from '../../hooks'
import { PolymorphicRefForwardingComponent } from '../../helpers'

export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
/**
* Component used for the root node. Either a string to use a HTML element or a component.
*/
as?: ElementType
/**
* A string of all className you want applied to the component.
*/
Expand DownExpand Up@@ -65,10 +70,14 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
const isOnMobile = (element: HTMLDivElement) =>
Boolean(getComputedStyle(element).getPropertyValue('--cui-is-mobile'))

export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
export const CSidebar: PolymorphicRefForwardingComponent<'div', CSidebarProps> = forwardRef<
HTMLDivElement,
CSidebarProps
>(
(
{
children,
as: Component = 'div',
className,
colorScheme,
narrow,
Expand DownExpand Up@@ -183,7 +192,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(

return (
<>
<div
<Component
className={classNames(
'sidebar',
{
Expand All@@ -203,7 +212,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
ref={forkedRef}
>
{children}
</div>
</Component>
{typeof window !== 'undefined' &&
mobile &&
createPortal(
Expand All@@ -216,6 +225,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
)

CSidebar.propTypes = {
as: PropTypes.elementType,
children: PropTypes.node,
className: PropTypes.string,
colorScheme: PropTypes.oneOf(['dark', 'light']),
Expand All@@ -231,4 +241,4 @@ CSidebar.propTypes = {
visible: PropTypes.bool,
}

CSidebar.displayName = 'CSidebar'
CSidebar.displayName = 'CSidebar'

[8]ページ先頭

©2009-2025 Movatter.jp