-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Panel: Convert to TypeScript #47259
Panel: Convert to TypeScript #47259
Changes from all commits
3a3f0fc
0a6180c
392357d
5ebc0a4
7c34e48
aa1336b
20374cc
edab3c1
16431d2
3346967
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { PanelHeaderProps } from './types'; | ||
|
||
/** | ||
* `PanelHeader` renders the header for the `Panel`. | ||
* This is used by the `Panel` component under the hood, | ||
* so it does not typically need to be used. | ||
*/ | ||
function PanelHeader( { label, children }: PanelHeaderProps ) { | ||
return ( | ||
<div className="components-panel__header"> | ||
{ label && <h2>{ label }</h2> } | ||
{ children } | ||
</div> | ||
); | ||
} | ||
|
||
export default PanelHeader; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PanelHeader from './header'; | ||
import type { PanelProps } from './types'; | ||
|
||
function UnforwardedPanel( | ||
{ header, className, children }: PanelProps, | ||
ref: React.ForwardedRef< HTMLDivElement > | ||
) { | ||
const classNames = classnames( className, 'components-panel' ); | ||
return ( | ||
<div className={ classNames } ref={ ref }> | ||
{ header && <PanelHeader label={ header } /> } | ||
{ children } | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* `Panel` expands and collapses multiple sections of content. | ||
* | ||
* ```jsx | ||
* import { Panel, PanelBody, PanelRow } from '@wordpress/components'; | ||
* import { more } from '@wordpress/icons'; | ||
* | ||
* const MyPanel = () => ( | ||
* <Panel header="My Panel"> | ||
* <PanelBody title="My Block Settings" icon={ more } initialOpen={ true }> | ||
* <PanelRow>My Panel Inputs and Labels</PanelRow> | ||
* </PanelBody> | ||
* </Panel> | ||
* ); | ||
* ``` | ||
*/ | ||
export const Panel = forwardRef( UnforwardedPanel ); | ||
|
||
export default Panel; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { forwardRef } from '@wordpress/element'; | ||
import type { ForwardedRef } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { PanelRowProps } from './types'; | ||
|
||
function UnforwardedPanelRow( | ||
{ className, children }: PanelRowProps, | ||
ref: ForwardedRef< HTMLDivElement > | ||
) { | ||
return ( | ||
<div | ||
className={ classnames( 'components-panel__row', className ) } | ||
ref={ ref } | ||
> | ||
{ children } | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* `PanelRow` is a generic container for rows within a `PanelBody`. | ||
* It is a flex container with a top margin for spacing. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that these info can be useful for a dev using this component, but should we expose implementation details like layout APIs (flex) and design details (margin top) ? An interesting dilemma, I personally don't have a strong opinion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this one I decided it was necessary to mention because it's essential to what PanelRow is. Those two styles are the only reason the component exists, and I phrased it in a way that we can stick to as a contract. In other words, if it ceases to be a flex container, or if it ceases to have a top margin, I would consider it a breaking change. |
||
*/ | ||
export const PanelRow = forwardRef( UnforwardedPanelRow ); | ||
|
||
export default PanelRow; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import Panel from '../'; | ||
import PanelRow from '../row'; | ||
import PanelBody from '../body'; | ||
import InputControl from '../../input-control'; | ||
|
||
/** | ||
* WordPress dependencies | ||
|
@@ -56,6 +57,27 @@ Default.args = { | |
), | ||
}; | ||
|
||
/** | ||
* `PanelRow` is a generic container for rows within a `PanelBody`. | ||
* It is a flex container with a top margin for spacing. | ||
*/ | ||
export const _PanelRow = Template.bind( {} ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this story to clarify what the default styling of PanelRow looks like. I don't quite understand why it is Though I'm wondering whether we can somehow salvage and update this component to use as #43423 π€ Something to think about! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I think that |
||
_PanelRow.args = { | ||
children: ( | ||
<PanelBody title="My Profile"> | ||
<PanelRow> | ||
<InputControl label="First name" /> | ||
<InputControl label="Last name" /> | ||
</PanelRow> | ||
<PanelRow> | ||
<div style={ { flex: 1 } }> | ||
<InputControl label="Email" /> | ||
</div> | ||
</PanelRow> | ||
</PanelBody> | ||
), | ||
}; | ||
|
||
export const DisabledSection = Template.bind( {} ); | ||
DisabledSection.args = { | ||
...Default.args, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export type PanelProps = { | ||
/** | ||
* The text that will be rendered as the title of the panel. | ||
* Text will be rendered inside an `<h2>` tag. | ||
*/ | ||
header?: PanelHeaderProps[ 'label' ]; | ||
/** | ||
* The CSS class to apply to the wrapper element. | ||
*/ | ||
className?: string; | ||
/** | ||
* The content to display within the panel. | ||
*/ | ||
children: React.ReactNode; | ||
}; | ||
|
||
export type PanelHeaderProps = { | ||
/** | ||
* The text that will be rendered as the title of the panel. | ||
* Will be rendered in an `<h2>` tag. | ||
*/ | ||
label?: string; | ||
/** | ||
* The content to display within the panel header. | ||
*/ | ||
children?: React.ReactNode; | ||
}; | ||
|
||
export type PanelRowProps = { | ||
/** | ||
* The CSS class to apply to the wrapper element. | ||
*/ | ||
className?: string; | ||
/** | ||
* The content to display within the panel row. | ||
*/ | ||
children: React.ReactNode; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not going to add
PanelHeader
the Storybook for now because it shouldn't really be used independently. No usages in the repo either. If it weren't for back compat I would remove it from the public exports.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider deprecating it to discourage further usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, I doubt anyone is using it because there is no reason to π So it's not that I want to discourage people from using it per se, it's more that I don't want to clutter our docs with something that is irrelevant to 99.9% of people.