Skip to content

Commit a53f099

Browse files
committed
refactor: rename otp slot to otp cell
1 parent 04fedd1 commit a53f099

7 files changed

Lines changed: 95 additions & 95 deletions

File tree

packages/core/src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const FieldTypePrefixes = {
2222
DateTimeSegment: 'dts',
2323
Calendar: 'cal',
2424
OTPField: 'otp',
25-
OTPSlot: 'otps',
25+
OtpCell: 'otpc',
2626
FileField: 'ff',
2727
FlowSegment: 'fs',
2828
} as const;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './useOtpField';
2-
export * from './useOtpSlot';
2+
export * from './useOtpCell';
33
export * from './useOtpControl';
44
export * from './types';

packages/core/src/useOtpField/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { InjectionKey } from 'vue';
22

3-
export type OtpSlotAcceptType = 'all' | 'numeric' | 'alphanumeric';
3+
export type OtpCellAcceptType = 'all' | 'numeric' | 'alphanumeric';
44

5-
export interface OtpSlotRegistration {
5+
export interface OtpCellRegistration {
66
id: string;
77
focusNext(): void;
88
focusPrevious(): void;
@@ -12,7 +12,7 @@ export interface OtpSlotRegistration {
1212
}
1313

1414
export interface OtpContext {
15-
useSlotRegistration(): OtpSlotRegistration;
15+
useCellRegistration(): OtpCellRegistration;
1616
getMaskCharacter(): string;
1717
onBlur(): void;
1818
}

packages/core/src/useOtpField/useOtpSlot.spec.ts renamed to packages/core/src/useOtpField/useOtpCell.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OtpSlot } from '.';
1+
import { OtpCell } from '.';
22
import { describe, expect, test, vi } from 'vitest';
33
import { appRender } from '@test-utils/index';
44

@@ -8,14 +8,14 @@ describe('useOtpSlot', () => {
88
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
99
// Render OtpSlot without a parent OtpField
1010
appRender({
11-
components: { OtpSlot },
12-
template: `<OtpSlot value="" />`,
11+
components: { OtpCell },
12+
template: `<OtpCell value="" />`,
1313
});
1414

1515
// Verify that the warning was shown
1616
// In browser mode this can be logged more than once depending on mount/render,
1717
// so assert on content rather than exact count.
18-
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('OtpSlot must be used within an OtpField'));
18+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('OtpCell must be used within an OtpField'));
1919

2020
warnSpy.mockRestore();
2121
});

packages/core/src/useOtpField/useOtpSlot.ts renamed to packages/core/src/useOtpField/useOtpCell.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@ import { Reactivify } from '../types';
33
import { hasKeyCode, isInputElement, normalizeProps, warn, useCaptureProps } from '../utils/common';
44
import { isFirefox } from '../utils/platform';
55
import { blockEvent } from '../utils/events';
6-
import { OtpContextKey, OtpSlotAcceptType } from './types';
6+
import { OtpContextKey, OtpCellAcceptType } from './types';
77
import { createDisabledContext } from '../helpers/createDisabledContext';
88
import { 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

Comments
 (0)