Skip to content
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

Revert "[PBNTR-373] (Enable Kits Instead of Text for Radio label)" #3682

Merged
merged 1 commit into from
Sep 11, 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
150 changes: 50 additions & 100 deletions playbook/app/pb_kits/playbook/pb_radio/_radio.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import React, { forwardRef, isValidElement, useRef } from 'react'
/*eslint-disable react/no-multi-comp, flowtype/space-before-type-colon */

import React, { forwardRef } from 'react'
import Body from '../pb_body/_body'
import Flex from '../pb_flex/_flex'
import classnames from 'classnames'
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
import { globalProps, GlobalProps } from '../utilities/globalProps'

type RadioProps = {
aria?: { [key: string]: string },
aria?: {[key: string]: string},
alignment?: string,
checked?: boolean,
children?: React.ReactChild[] | React.ReactChild,
className?: string,
dark?: boolean,
data?: { [key: string]: string },
data?: {[key: string]: string},
disabled?: boolean,
error?: boolean,
htmlOptions?: { [key: string]: string | number | boolean | (() => void) },
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
id?: string,
label: string,
name?: string,
value?: string,
text?: string,
onChange: (event: React.FormEvent<HTMLInputElement> | null) => void,
onChange: (event: React.FormEvent<HTMLInputElement> | null)=>void,
} & GlobalProps

const Radio = ({
Expand All @@ -30,9 +31,9 @@ const Radio = ({
children,
className,
dark = false,
data = {},
disabled = false,
error = false,
data = {},
htmlOptions = {},
id,
label,
Expand All @@ -41,103 +42,52 @@ const Radio = ({
value = 'radio_text',
onChange = () => { void 0 },
...props
}: RadioProps ) => {
const radioRef = useRef(null);

const ariaProps = buildAriaProps(aria);
const dataProps = buildDataProps(data);
const htmlProps = buildHtmlProps(htmlOptions);
}: RadioProps, ref: any) => {
const ariaProps = buildAriaProps(aria)
const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
const classes = classnames(
buildCss('pb_radio_kit', alignment),
dark ? 'dark' : null,
error ? 'error' : null,
buildCss('pb_radio_kit', alignment ),
dark ? 'dark': null, error ? 'error': null,
globalProps(props),
className
);

const classesCustom = classnames(
dark ? 'dark' : null,
error ? 'error' : null,
globalProps(props),
className
);

const isCustomChild = children && isValidElement(children) && children.type !== 'input';
className)

const displayRadio = (props: RadioProps & any) => {
if (isValidElement(children) && children.type === 'input') {
return children;
} else if (isCustomChild || !children) {
return (
<input
disabled={disabled}
id={id}
name={name}
onChange={onChange}
ref={radioRef}
text={text}
type="radio"
value={value}
{...props}
/>
);
}
};

const handleContainerClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent> | undefined) => {
if (event) {
const target = event.target as HTMLElement;
if (
target.id === 'pb-radio-children-wrapper' ||
target.closest('#pb-radio-children-wrapper')
) {
radioRef.current?.click();
}
}
};
if (children)
return (children)
else
return (
<input
disabled={disabled}
id={id}
name={name}
onChange={onChange}
ref={ref}
text={text}
type="radio"
value={value}
{...props}
/>
)}

return (
isCustomChild ? (
<Flex
{...ariaProps}
{...dataProps}
{...htmlProps}
align='center'
className={classesCustom}
cursor='pointer'
htmlFor={id}
htmlOptions={{
onClick: ((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
handleContainerClick(event);
}) as unknown as () => void
}}
id="radio-container"
>
<label className={buildCss('pb_radio_kit', alignment)}>
<>{displayRadio(props)}</>
<span className="pb_radio_button" />
</label>
<div id="pb-radio-children-wrapper"> {children} </div>
</Flex>
) : (
<label
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classes}
htmlFor={id}
>
<>{displayRadio(props)}</>
<span className="pb_radio_button" />
<Body
dark={dark}
status={error ? 'negative' : null}
text={label}
variant={null}
/>
</label>
)
);
};
<label
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classes}
htmlFor={id}
>
<>{displayRadio(props)}</>
<span className="pb_radio_button" />
<Body
dark={dark}
status={error ? 'negative' : null}
text={label}
variant={null}
/>
</label>
)
}

export default forwardRef(Radio);
export default forwardRef(Radio)
56 changes: 0 additions & 56 deletions playbook/app/pb_kits/playbook/pb_radio/docs/_radio_children.jsx

This file was deleted.

1 change: 0 additions & 1 deletion playbook/app/pb_kits/playbook/pb_radio/docs/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ examples:
- radio_error: With Error
- radio_alignment: Alignment
- radio_disabled: Disabled
- radio_children: Children

swift:
- radio_default_swift: Default
Expand Down
1 change: 0 additions & 1 deletion playbook/app/pb_kits/playbook/pb_radio/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export { default as RadioCustom } from './_radio_custom.jsx'
export { default as RadioError } from './_radio_error.jsx'
export { default as RadioAlignment } from './_radio_alignment.jsx'
export { default as RadioDisabled } from './_radio_disabled.jsx'
export { default as RadioChildren } from './_radio_children.jsx'
Loading