Skip to content

Commit db0c37d

Browse files
committed
expose classnames for selecting
1 parent e1fc30d commit db0c37d

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

src/components/forms/uncontrolled/index.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,27 @@ export * from './inputs';
88
* form element
99
*/
1010
type FormProps = React.ComponentPropsWithoutRef<'form'>;
11+
export const formClassName = 'uncontrolled-form';
1112
export const Form = ({children, className, style, ...props}: FormProps) => {
1213
return (
13-
<form className={`uncontrolled-form ${className || ''}`} style={style} {...props}>
14+
<form className={[formClassName, className].join(' ').trim()} style={style} {...props}>
1415
{children}
1516
</form>
1617
);
1718
};
1819

20+
export const formSectionClassName = 'uncontrolled-form-section';
1921
export const FormSection = ({className, ...props}: React.ComponentPropsWithoutRef<'div'>) => (
20-
<div className={`uncontrolled-form-section ${className || ''}`} {...props} />
22+
<div className={[formSectionClassName, className].join(' ').trim()} {...props} />
2123
);
2224

2325
type MessagesProps = {
2426
state: FetchState<any, string>;
2527
className?: string;
2628
};
29+
export const messagesClassName = 'uncontrolled-messages';
2730
export const Messages = ({state, className}: MessagesProps) => stateHasError(state)
28-
? <div className={`uncontrolled-messages ${className || ''}`}>{state.error}</div>
31+
? <div className={[messagesClassName, className].join(' ').trim()}>{state.error}</div>
2932
: null;
3033

3134
/*
@@ -36,18 +39,22 @@ type ButtonsProps = {
3639
onCancel?: () => void;
3740
className?: string;
3841
};
39-
export const Buttons = (props: ButtonsProps) => (
40-
<div className={`uncontrolled-buttons ${props.className || ''}`}>
42+
export const buttonsClassName = 'uncontrolled-buttons';
43+
export const Buttons = ({className, ...props}: ButtonsProps) => (
44+
<div className={[buttonsClassName, className].join(' ').trim()}>
4145
{'onCancel' in props ? <Cancel onClick={props.onCancel}>Cancel</Cancel> : null}
4246
<Submit />
4347
</div>
4448
);
4549

4650
// submit button
4751
type SubmitButtonProps = React.ComponentPropsWithoutRef<'input'>;
48-
export const Submit = ({...props}: SubmitButtonProps) =>
49-
<input type="submit" value="Submit" {...props} />;
52+
export const submitButtonClassName = 'uncontrolled-submit-button';
53+
export const Submit = ({className, ...props}: SubmitButtonProps) =>
54+
<input className={[submitButtonClassName, className].join(' ').trim()} type="submit" value="Submit" {...props} />;
5055

5156
// cancel button
5257
type CancelButtonProps = React.ComponentPropsWithoutRef<'button'>;
53-
export const Cancel = ({...props}: CancelButtonProps) => <button type="button" {...props} />;
58+
export const cancelButtonClassName = 'uncontrolled-cancel-button';
59+
export const Cancel = ({className, ...props}: CancelButtonProps) =>
60+
<button className={[cancelButtonClassName, className].join(' ').trim()} type="button" {...props} />;

src/components/forms/uncontrolled/inputDecorations.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import React from 'react';
2-
import classNames from 'classnames';
32
import './inputDecorations.css';
43

4+
export const formInputWrapperClassName = 'uncontrolled-form-input-wrapper';
55
export const FormInputWrapper = React.forwardRef<
66
HTMLElement,
77
React.ComponentPropsWithoutRef<'label'> & { as?: string }
88
>(({className, as: Element = 'label', ...props}, ref) => (
9-
React.createElement(Element, {ref, className: classNames('uncontrolled-form-input-wrapper', className), ...props})
9+
React.createElement(Element, {ref, className: [formInputWrapperClassName, className].join(' ').trim(), ...props})
1010
));
1111
FormInputWrapper.displayName = 'FormInputWrapper';
1212

13+
export const formLabelTextClassName = 'uncontrolled-form-label-text';
1314
export const FormLabelText = ({className, as: Element = 'span', ...props}: React.ComponentPropsWithoutRef<'span'> & { as?: string }) => (
14-
React.createElement(Element, {className: classNames('uncontrolled-form-label-text', className), ...props})
15+
React.createElement(Element, {className: [formLabelTextClassName, className].join(' ').trim(), ...props})
1516
);
1617

1718
export type InputProps = {
@@ -25,8 +26,9 @@ export type InputProps = {
2526
type HelpTextProps = React.ComponentPropsWithoutRef<'p'> & {
2627
value: string | undefined | React.ReactNode;
2728
};
29+
export const helpTextClassName = 'uncontrolled-help-text';
2830
export const HelpText = ({value, className, as: Element = 'p', ...props}: HelpTextProps & { as?: string }) => value
29-
? React.createElement(Element, {className: classNames('uncontrolled-help-text', className), ...props}, value)
31+
? React.createElement(Element, {className: [helpTextClassName, className].join(' ').trim(), ...props}, value)
3032
: null;
3133

3234
export const RequiredIndicator = (props: {show: boolean | undefined}) => props.show ? <>*</> : null;

0 commit comments

Comments
 (0)