/* * The MIT License (MIT) * * Copyright (c) 2015 - present Instructure, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import React from 'react' import type { InputHTMLAttributes } from 'react' import type { OtherHTMLAttributes } from '@instructure/shared-types' import type { ComponentStyle, NewThemeOverrideProp, Spacing } from '@instructure/emotion' import type { WithDeterministicIdProps } from '@instructure/ui-react-utils' import type { NewComponentTypes } from '@instructure/ui-themes' type RadioInputOwnProps = { /** * The label displayed next to the checkbox */ label: React.ReactNode /** * This maps to the low level HTML attribute * [with the same name](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#value) */ value?: string | number /** * The id of the input element. If not provided, a unique id will be generated. */ id?: string /** * The [name](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#defining_a_radio_group) * defines which group it belongs to, it's managed by the `RadioInputGroup` * this component belongs to. * * Do not set it manually. */ name?: string /** * Sets the `checked` prop of the underlying input element. If left undefined, * the component will control its own state. */ checked?: boolean /** * Whether to disable the input */ disabled?: boolean /** * Works just like disabled but keeps the same styles as if it were active */ readOnly?: boolean /** * The visual style of the radio button */ variant?: 'simple' | 'toggle' size?: 'small' | 'medium' | 'large' /** * Sets the background color of the radio button when `variant="toggle"` */ context?: 'success' | 'warning' | 'danger' | 'off' /** * Sets the `display:inline-flex` in CSS */ inline?: boolean /** * Valid values are `0`, `none`, `auto`, and Spacing token values, * see https://instructure.design/layout-spacing. Apply these values via * familiar CSS-like shorthand. For example, `margin="general.spaceMd auto"`. */ margin?: Spacing onClick?: (event: React.MouseEvent) => void /** * Callback fired when the input fires a change event. * event.target.value will contain the new value. It will always be a string. */ onChange?: (event: React.ChangeEvent) => void /** * A function that provides a reference to the actual underlying input element */ inputRef?: (inputElement: HTMLInputElement | null) => void } type PropKeys = keyof RadioInputOwnProps type AllowedPropKeys = Readonly> type RadioInputProps = RadioInputOwnProps & NewThemeOverrideProp> & OtherHTMLAttributes< RadioInputOwnProps, InputHTMLAttributes > & WithDeterministicIdProps type RadioInputStyle = ComponentStyle<'radioInput' | 'input' | 'label'> type RadioInputState = { checked?: boolean } const allowedProps: AllowedPropKeys = [ 'label', 'value', 'id', 'name', 'checked', 'disabled', 'readOnly', 'variant', 'size', 'context', 'inline', 'margin', 'onClick', 'onChange', 'inputRef' ] export type { RadioInputProps, RadioInputState, RadioInputStyle } export { allowedProps }