💄Remove on-focus border for the select and radiobutton inputs

This commit is contained in:
Anton SHEPILOV
2024-05-07 15:16:34 +02:00
committed by ericlinagora
parent e1d6788cd2
commit 9ead8efee6
2 changed files with 27 additions and 11 deletions
@@ -1,17 +1,27 @@
import { isUndefined } from "lodash";
interface CheckboxSliderProps extends React.InputHTMLAttributes<HTMLInputElement> { interface CheckboxSliderProps extends React.InputHTMLAttributes<HTMLInputElement> {
checked?: boolean; checked?: boolean;
disabled?: boolean; disabled?: boolean;
noFocusBorder?: boolean;
} }
/** Just classes up a checkbox to look like a slider. Deviates from onChange etc for /** Just classes up a checkbox to look like a slider. Deviates from onChange etc for
* compatibility with `InputHTMLAttributes<HTMLInputElement>`, to expose eg. id to use with htmlFor. * compatibility with `InputHTMLAttributes<HTMLInputElement>`, to expose eg. id to use with htmlFor.
*/ */
export const CheckboxSlider = (props: CheckboxSliderProps) => export const CheckboxSlider = (props: CheckboxSliderProps) => {
<input let styles = {};
{...props} const noFocus = isUndefined(props.noFocusBorder) ? true : props.noFocusBorder;
type="checkbox" if (noFocus) styles = {boxShadow: "none", borderColor: "inherit"};
role="switch"
// @author https://tw-elements.com/docs/react/forms/switch/ return (
className="!bg-none mr-2 mt-[0.3rem] h-7 w-14 appearance-none rounded-[0.9rem] bg-neutral-300 before:pointer-events-none before:absolute before:h-7 before:w-5 before:rounded-full before:bg-transparent before:content-[''] after:absolute after:z-[2] after:mt-[0.2rem] after:ml-[0.2rem] after:h-5 after:w-5 after:rounded-full after:border-none after:bg-neutral-100 after:shadow-[0_0px_3px_0_rgb(0_0_0_/_7%),_0_2px_2px_0_rgb(0_0_0_/_4%)] after:transition-[background-color_0.2s,transform_0.2s] after:content-[''] checked:bg-primary checked:after:absolute checked:after:z-[2] checked:after:ml-[1.9625rem] checked:after:w-5 checked:after:rounded-full checked:after:border-none checked:after:bg-primary checked:after:shadow-[0_3px_1px_-2px_rgba(0,0,0,0.2),_0_2px_2px_0_rgba(0,0,0,0.14),_0_1px_5px_0_rgba(0,0,0,0.12)] checked:after:transition-[background-color_0.2s,transform_0.2s] checked:after:content-[''] hover:cursor-pointer dark:bg-neutral-600 dark:after:bg-white dark:checked:bg-primary dark:checked:after:bg-primary disabled:cursor-default disabled:opacity-25 !focus:shadow-none" <input
checked={!!props.checked} {...props}
disabled={props.disabled} type="checkbox"
/>; role="switch"
style={styles}
// @author https://tw-elements.com/docs/react/forms/switch/
className="!bg-none mr-2 mt-[0.3rem] h-7 w-14 appearance-none rounded-[0.9rem] bg-neutral-300 before:pointer-events-none before:absolute before:h-7 before:w-5 before:rounded-full before:bg-transparent before:content-[''] after:absolute after:z-[2] after:mt-[0.2rem] after:ml-[0.2rem] after:h-5 after:w-5 after:rounded-full after:border-none after:bg-neutral-100 after:shadow-[0_0px_3px_0_rgb(0_0_0_/_7%),_0_2px_2px_0_rgb(0_0_0_/_4%)] after:transition-[background-color_0.2s,transform_0.2s] after:content-[''] checked:bg-primary checked:after:absolute checked:after:z-[2] checked:after:ml-[1.9625rem] checked:after:w-5 checked:after:rounded-full checked:after:border-none checked:after:bg-primary checked:after:shadow-[0_3px_1px_-2px_rgba(0,0,0,0.2),_0_2px_2px_0_rgba(0,0,0,0.14),_0_1px_5px_0_rgba(0,0,0,0.12)] checked:after:transition-[background-color_0.2s,transform_0.2s] checked:after:content-[''] hover:cursor-pointer dark:bg-neutral-600 dark:after:bg-white dark:checked:bg-primary dark:checked:after:bg-primary disabled:cursor-default disabled:opacity-25 !focus:shadow-none"
checked={!!props.checked}
disabled={props.disabled}
/>)
}
@@ -1,4 +1,4 @@
import _ from 'lodash'; import _, { isUndefined } from "lodash";
import { defaultInputClassName, errorInputClassName, ThemeName } from './input-text'; import { defaultInputClassName, errorInputClassName, ThemeName } from './input-text';
export type SelectSize = 'md' | 'lg' | 'sm'; export type SelectSize = 'md' | 'lg' | 'sm';
@@ -9,6 +9,7 @@ interface InputProps extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>,
size?: SelectSize; size?: SelectSize;
className?: string; className?: string;
children?: React.ReactNode; children?: React.ReactNode;
noFocusBorder?: boolean;
} }
export function Select(props: InputProps) { export function Select(props: InputProps) {
@@ -21,8 +22,13 @@ export function Select(props: InputProps) {
else if (props.size === 'sm') inputClassName = inputClassName + ' text-sm h-7 py-0 px-3'; else if (props.size === 'sm') inputClassName = inputClassName + ' text-sm h-7 py-0 px-3';
else inputClassName = inputClassName + ' text-base h-9 py-1'; else inputClassName = inputClassName + ' text-base h-9 py-1';
let styles = {};
const noFocus = isUndefined(props.noFocusBorder) ? true : props.noFocusBorder;
if (noFocus) styles = {boxShadow: "none", borderColor: "inherit"};
return ( return (
<select <select
style={styles}
className={inputClassName + ' ' + props.className} className={inputClassName + ' ' + props.className}
{..._.omit(props, 'label', 'className', 'size')} {..._.omit(props, 'label', 'className', 'size')}
> >