@@ -3,49 +3,49 @@ import { Reactivify } from '../types';
33import { hasKeyCode , isInputElement , normalizeProps , warn , useCaptureProps } from '../utils/common' ;
44import { isFirefox } from '../utils/platform' ;
55import { blockEvent } from '../utils/events' ;
6- import { OtpContextKey , OtpSlotAcceptType } from './types' ;
6+ import { OtpContextKey , OtpCellAcceptType } from './types' ;
77import { createDisabledContext } from '../helpers/createDisabledContext' ;
88import { isValueAccepted } from './utils' ;
99
10- export interface OtpSlotProps {
10+ export interface OtpCellProps {
1111 /**
12- * The value of the slot .
12+ * The value of the cell .
1313 */
1414 value : string ;
1515
1616 /**
17- * Whether the slot is disabled.
17+ * Whether the cell is disabled.
1818 */
1919 disabled ?: boolean ;
2020
2121 /**
22- * Whether the slot is readonly.
22+ * Whether the cell is readonly.
2323 */
2424 readonly ?: boolean ;
2525
2626 /**
27- * Whether the slot is masked.
27+ * Whether the cell is masked.
2828 */
2929 masked ?: boolean ;
3030
3131 /**
32- * The type of the slot .
32+ * The type of the cell .
3333 */
34- accept ?: OtpSlotAcceptType ;
34+ accept ?: OtpCellAcceptType ;
3535}
3636
37- export function useOtpSlot ( _props : Reactivify < OtpSlotProps > ) {
37+ export function useOtpCell ( _props : Reactivify < OtpCellProps > ) {
3838 const props = normalizeProps ( _props ) ;
39- const slotEl = shallowRef < HTMLElement > ( ) ;
39+ const cellEl = shallowRef < HTMLElement > ( ) ;
4040 const isDisabled = createDisabledContext ( props . disabled ) ;
4141
4242 const context = inject ( OtpContextKey , null ) ;
4343
44- const registration = context ?. useSlotRegistration ( ) ;
44+ const registration = context ?. useCellRegistration ( ) ;
4545
4646 if ( ! context ) {
4747 if ( __DEV__ ) {
48- warn ( 'OtpSlot must be used within an OtpField' ) ;
48+ warn ( 'OtpCell must be used within an OtpField' ) ;
4949 }
5050 }
5151
@@ -58,16 +58,16 @@ export function useOtpSlot(_props: Reactivify<OtpSlotProps>) {
5858 }
5959
6060 function setElementValue ( value : string ) {
61- if ( ! slotEl . value ) {
61+ if ( ! cellEl . value ) {
6262 return ;
6363 }
6464
65- if ( isInputElement ( slotEl . value ) ) {
66- slotEl . value . value = value ;
65+ if ( isInputElement ( cellEl . value ) ) {
66+ cellEl . value . value = value ;
6767 return ;
6868 }
6969
70- slotEl . value . textContent = value ;
70+ cellEl . value . textContent = value ;
7171 }
7272
7373 const handlers = {
@@ -129,28 +129,28 @@ export function useOtpSlot(_props: Reactivify<OtpSlotProps>) {
129129 }
130130 } ,
131131 onChange ( e : Event ) {
132- if ( ! slotEl . value ) {
132+ if ( ! cellEl . value ) {
133133 return ;
134134 }
135135
136- if ( isInputElement ( slotEl . value ) ) {
137- setElementValue ( slotEl . value . value ) ;
138- registration ?. setValue ( slotEl . value . value , e ) ;
136+ if ( isInputElement ( cellEl . value ) ) {
137+ setElementValue ( cellEl . value . value ) ;
138+ registration ?. setValue ( cellEl . value . value , e ) ;
139139 return ;
140140 }
141141
142- setElementValue ( slotEl . value . textContent ?? '' ) ;
143- registration ?. setValue ( slotEl . value . textContent ?? '' , e ) ;
142+ setElementValue ( cellEl . value . textContent ?? '' ) ;
143+ registration ?. setValue ( cellEl . value . textContent ?? '' , e ) ;
144144 } ,
145145 } ;
146146
147- const slotProps = useCaptureProps ( ( ) => {
148- const isInput = isInputElement ( slotEl . value ) ;
147+ const cellProps = useCaptureProps ( ( ) => {
148+ const isInput = isInputElement ( cellEl . value ) ;
149149
150150 const baseProps : Record < string , unknown > = {
151151 [ isInput ? 'readonly' : 'aria-readonly' ] : toValue ( props . readonly ) ,
152152 [ isInput ? 'disabled' : 'aria-disabled' ] : toValue ( props . disabled ) ,
153- 'data-otp-slot ' : true ,
153+ 'data-otp-cell ' : true ,
154154 spellcheck : false ,
155155 tabindex : isDisabled . value ? '-1' : '0' ,
156156 autocorrect : 'off' ,
@@ -175,24 +175,24 @@ export function useOtpSlot(_props: Reactivify<OtpSlotProps>) {
175175 }
176176
177177 return baseProps ;
178- } , slotEl ) ;
178+ } , cellEl ) ;
179179
180180 return {
181- slotProps ,
181+ cellProps ,
182182 key : registration ?. id ?? useId ( ) ,
183183 value : computed ( ( ) => withMask ( toValue ( props . value ) ) ) ,
184184 } ;
185185}
186186
187187/**
188- * A helper component that renders an OTP slot . You can build your own with `useOtpSlot `.
188+ * A helper component that renders an OTP cell . You can build your own with `useOtpCell `.
189189 */
190- export const OtpSlot = /*#__PURE__*/ defineComponent < OtpSlotProps & { as ?: string } > ( {
191- name : 'OtpSlot ' ,
190+ export const OtpCell = /*#__PURE__*/ defineComponent < OtpCellProps & { as ?: string } > ( {
191+ name : 'OtpCell ' ,
192192 props : [ 'value' , 'disabled' , 'readonly' , 'accept' , 'masked' , 'as' ] ,
193193 setup ( props ) {
194- const { slotProps , value, key } = useOtpSlot ( props ) ;
194+ const { cellProps , value, key } = useOtpCell ( props ) ;
195195
196- return ( ) => h ( props . as || 'input' , { ...slotProps . value , key } , value . value ) ;
196+ return ( ) => h ( props . as || 'input' , { ...cellProps . value , key } , value . value ) ;
197197 } ,
198198} ) ;
0 commit comments