@xsolla/xui-counter 0.200.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/native/index.d.mts +130 -0
- package/native/index.d.ts +130 -0
- package/native/index.js +676 -0
- package/native/index.js.map +1 -0
- package/native/index.mjs +646 -0
- package/native/index.mjs.map +1 -0
- package/package.json +59 -0
- package/web/index.d.mts +130 -0
- package/web/index.d.ts +130 -0
- package/web/index.js +696 -0
- package/web/index.js.map +1 -0
- package/web/index.mjs +659 -0
- package/web/index.mjs.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Counter.tsx","../../../../foundation/primitives-native/src/Box.tsx","../../../../foundation/primitives-native/src/Text.tsx","../../../../foundation/primitives-native/src/Icon.tsx","../../../../foundation/primitives-native/src/index.tsx","../../src/utils.ts"],"sourcesContent":["import React, { forwardRef, useRef, useState } from \"react\";\n// @ts-expect-error - this will be resolved at build time\nimport { Box, Text, Icon, isWeb } from \"@xsolla/xui-primitives\";\nimport { useResolvedTheme, useId } from \"@xsolla/xui-core\";\nimport { Input } from \"@xsolla/xui-input\";\nimport { MinusSq, PlusSq } from \"@xsolla/xui-icons-base\";\nimport type { CounterProps } from \"./types\";\nimport {\n COUNTER_SIZE_CONFIG,\n allowsNegative,\n clampToRange,\n parseCounterValue,\n sanitizeCounterInput,\n} from \"./utils\";\n\ninterface CounterButtonProps {\n icon: React.ReactNode;\n label: string;\n onPress: () => void;\n available: boolean;\n boxSize: number;\n borderRadius: number;\n color: string;\n hoverColor: string;\n testID?: string;\n}\n\nconst CounterButton: React.FC<CounterButtonProps> = ({\n icon,\n label,\n onPress,\n available,\n boxSize,\n borderRadius,\n color,\n hoverColor,\n testID,\n}) => (\n <Box\n as=\"button\"\n type=\"button\"\n width={boxSize}\n height={boxSize}\n flexShrink={0}\n alignItems=\"center\"\n justifyContent=\"center\"\n padding={0}\n borderWidth={0}\n borderRadius={borderRadius}\n backgroundColor=\"transparent\"\n cursor={available ? \"pointer\" : \"not-allowed\"}\n disabled={!available}\n aria-disabled={!available || undefined}\n aria-label={label}\n // Keep a stable Pressable host on native even when unavailable so the\n // control stays in the a11y tree with a disabled state.\n onPress={onPress}\n hoverStyle={available ? { backgroundColor: hoverColor } : undefined}\n // Keep focus in the field so a click does not commit-then-step.\n {...(isWeb && {\n onMouseDown: (e: React.MouseEvent<HTMLButtonElement>) =>\n e.preventDefault(),\n })}\n data-testid={testID}\n testID={testID}\n >\n <Icon size={boxSize} color={color}>\n {icon}\n </Icon>\n </Box>\n);\n\n/**\n * A numeric stepper that lets the user increase or decrease a value using\n * dedicated − and + buttons.\n *\n * Counter has no error state: values outside the allowed range are never\n * rejected, they are silently clamped to the nearest bound on commit, so the\n * component is always in a valid state.\n */\nexport const Counter = forwardRef<HTMLInputElement, CounterProps>(\n (\n {\n value,\n defaultValue = null,\n onChange,\n min,\n max,\n step = 1,\n size = \"md\",\n type = \"input\",\n disabled = false,\n label,\n \"aria-label\": ariaLabel,\n decrementLabel = \"Decrease quantity\",\n incrementLabel = \"Increase quantity\",\n name,\n id: providedId,\n testID,\n themeMode,\n themeProductContext,\n },\n ref\n ) => {\n const { theme } = useResolvedTheme({ themeMode, themeProductContext });\n\n const rawId = useId();\n const safeId = rawId.replace(/:/g, \"\");\n const counterId = providedId || `counter-${safeId}`;\n\n const isControlled = value !== undefined;\n const [uncontrolledValue, setUncontrolledValue] = useState<number | null>(\n defaultValue\n );\n const committedValue = isControlled ? (value ?? null) : uncontrolledValue;\n\n // Text held while the user is mid-entry. `null` means \"show the committed\n // value\" — typing is never committed keystroke-by-keystroke.\n const [draft, setDraft] = useState<string | null>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n\n React.useImperativeHandle(\n ref,\n () => inputRef.current as HTMLInputElement,\n []\n );\n\n const sizeConfig = COUNTER_SIZE_CONFIG[size];\n const inputSizing = theme.sizing.input(size);\n const isReadOnly = type === \"readOnly\";\n\n // The value the buttons step from: an uncommitted draft wins over the last\n // committed value so typing 7 then pressing + lands on 8, not oldValue + 1.\n const pendingValue =\n draft !== null ? parseCounterValue(draft) : committedValue;\n const stepBase = pendingValue ?? min ?? 0;\n\n const canDecrement =\n !disabled && (typeof min !== \"number\" || stepBase > min);\n const canIncrement =\n !disabled && (typeof max !== \"number\" || stepBase < max);\n\n const commit = (next: number | null) => {\n setDraft(null);\n // An empty field on commit restores the previous value — the counter is\n // never left in an empty, indeterminate state after commit.\n const resolved = next ?? committedValue;\n if (resolved === null) return;\n const clamped = clampToRange(resolved, min, max);\n if (!isControlled) setUncontrolledValue(clamped);\n if (clamped !== committedValue) onChange?.(clamped);\n };\n\n const stepBy = (direction: 1 | -1) => {\n commit(clampToRange(stepBase + direction * step, min, max));\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n setDraft(sanitizeCounterInput(e.target.value, allowsNegative(min)));\n };\n\n const handleBlur = () => {\n commit(draft !== null ? parseCounterValue(draft) : committedValue);\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"ArrowUp\") {\n e.preventDefault();\n if (canIncrement) stepBy(1);\n return;\n }\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n if (canDecrement) stepBy(-1);\n return;\n }\n if (e.key === \"Home\" && typeof min === \"number\") {\n e.preventDefault();\n commit(min);\n return;\n }\n if (e.key === \"End\" && typeof max === \"number\") {\n e.preventDefault();\n commit(max);\n return;\n }\n // Native TextInput reports Return as \"Enter\" or \"\\n\" via onKeyPress.\n if (e.key === \"Enter\" || e.key === \"\\n\") {\n e.preventDefault();\n commit(draft !== null ? parseCounterValue(draft) : committedValue);\n }\n };\n\n const enabledIconColor = theme.colors.content.secondary;\n const disabledIconColor = theme.colors.control.text.disable;\n const hoverColor = theme.colors.overlay.mono;\n const buttonRadius = theme.shape.input[size].borderRadius;\n\n const decrementButton = (\n <CounterButton\n icon={<MinusSq />}\n label={decrementLabel}\n onPress={() => {\n if (canDecrement) stepBy(-1);\n }}\n available={canDecrement}\n boxSize={sizeConfig.control}\n borderRadius={buttonRadius}\n color={canDecrement ? enabledIconColor : disabledIconColor}\n hoverColor={hoverColor}\n testID={testID ? `${testID}__decrement` : undefined}\n />\n );\n\n const incrementButton = (\n <CounterButton\n icon={<PlusSq />}\n label={incrementLabel}\n onPress={() => {\n if (canIncrement) stepBy(1);\n }}\n available={canIncrement}\n boxSize={sizeConfig.control}\n borderRadius={buttonRadius}\n color={canIncrement ? enabledIconColor : disabledIconColor}\n hoverColor={hoverColor}\n testID={testID ? `${testID}__increment` : undefined}\n />\n );\n\n // Label sits above the whole control row (buttons + value), never inside\n // the Input between the buttons — that would push − / + off the field's\n // vertical center (Figma Counter has no in-component label; labels come\n // from FieldGroup / adjacent text, or this convenience prop).\n const labelId = `${counterId}-label`;\n const showLabel = Boolean(label) && !isReadOnly;\n const labelNode = showLabel ? (\n <Box as=\"label\" id={labelId}>\n <Text\n color={theme.colors.content.secondary}\n fontSize={inputSizing.fontSize - 2}\n fontWeight=\"500\"\n >\n {label}\n </Text>\n </Box>\n ) : null;\n\n if (isReadOnly) {\n // Read-only renders the value as plain text, never as a disabled or\n // `readonly` input — both would tell assistive technology the value\n // cannot change, which is false: the buttons still change it.\n const readOnlyValue = String(committedValue ?? min ?? 0);\n return (\n <Box\n flexDirection=\"row\"\n alignItems=\"center\"\n gap={sizeConfig.gap}\n width={sizeConfig.readOnlyWidth}\n role=\"group\"\n aria-label={ariaLabel || label}\n aria-disabled={disabled || undefined}\n data-testid={testID}\n >\n {decrementButton}\n <Box flex={1} minWidth={0} aria-live=\"polite\" alignItems=\"center\">\n <Text\n color={\n disabled\n ? theme.colors.control.input.textDisable\n : theme.colors.control.input.text\n }\n fontSize={inputSizing.fontSize}\n lineHeight={inputSizing.fontSize + 2}\n textAlign=\"center\"\n data-testid={testID ? `${testID}__value` : undefined}\n >\n {readOnlyValue}\n </Text>\n </Box>\n {incrementButton}\n </Box>\n );\n }\n\n const displayValue =\n draft !== null\n ? draft\n : committedValue === null\n ? \"\"\n : String(committedValue);\n\n return (\n <Box\n flexDirection=\"column\"\n gap={inputSizing.fieldGap}\n alignItems=\"flex-start\"\n role=\"group\"\n aria-label={showLabel ? undefined : ariaLabel}\n aria-labelledby={showLabel ? labelId : undefined}\n aria-disabled={disabled || undefined}\n data-testid={testID}\n >\n {labelNode}\n <Box\n flexDirection=\"row\"\n alignItems=\"center\"\n gap={sizeConfig.gap}\n width={sizeConfig.inputWidth}\n >\n {decrementButton}\n <Box flex={1} minWidth={0}>\n <Input\n ref={inputRef}\n id={counterId}\n name={name}\n size={size}\n value={displayValue}\n disabled={disabled}\n onChange={handleInputChange}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n // `type=\"text\"` + `inputMode=\"numeric\"`, not `type=\"number\"`,\n // which would add the browser's own spinners next to ours.\n type=\"text\"\n inputMode=\"numeric\"\n role=\"spinbutton\"\n aria-valuenow={committedValue ?? undefined}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-label={showLabel ? undefined : ariaLabel}\n {...(showLabel ? { \"aria-labelledby\": labelId } : {})}\n // Figma centers the value in the compact field.\n style={{ textAlign: \"center\" }}\n themeMode={themeMode}\n themeProductContext={themeProductContext}\n testID={testID ? `${testID}__input` : undefined}\n />\n </Box>\n {incrementButton}\n </Box>\n </Box>\n );\n }\n);\n\nCounter.displayName = \"Counter\";\n","import React from \"react\";\nimport {\n View,\n Pressable,\n Image,\n ViewStyle,\n ImageStyle,\n DimensionValue,\n AnimatableNumericValue,\n AccessibilityRole,\n} from \"react-native\";\nimport { BoxProps } from \"@xsolla/xui-primitives-core\";\n\nconst roleToAccessibilityRole: Record<string, AccessibilityRole> = {\n button: \"button\",\n link: \"link\",\n img: \"image\",\n image: \"image\",\n summary: \"summary\",\n switch: \"switch\",\n checkbox: \"checkbox\",\n radio: \"radio\",\n heading: \"header\",\n text: \"text\",\n search: \"search\",\n alert: \"alert\",\n none: \"none\",\n presentation: \"none\",\n progressbar: \"progressbar\",\n scrollbar: \"scrollbar\",\n adjustable: \"adjustable\",\n tab: \"tab\",\n menu: \"menu\",\n menuitem: \"menuitem\",\n list: \"list\",\n timer: \"timer\",\n};\n\n/** RN ViewStyle.gap is typed as number (Yoga gap), not DimensionValue. */\nconst toGapValue = (gap: number | string | undefined): number | undefined => {\n if (gap === undefined) return undefined;\n if (typeof gap === \"number\") return gap;\n const pxMatch = /^(\\d+(?:\\.\\d+)?)px$/.exec(gap);\n if (pxMatch) return Number(pxMatch[1]);\n const asNumber = Number(gap);\n return Number.isFinite(asNumber) ? asNumber : undefined;\n};\n\nexport const Box: React.FC<BoxProps> = ({\n children,\n onPress,\n onLayout,\n onMoveShouldSetResponder,\n onResponderGrant,\n onResponderMove,\n onResponderRelease,\n onResponderTerminate,\n backgroundColor,\n borderColor,\n borderWidth,\n borderBottomWidth,\n borderBottomColor,\n borderTopWidth,\n borderTopColor,\n borderLeftWidth,\n borderLeftColor,\n borderRightWidth,\n borderRightColor,\n borderRadius,\n borderStyle,\n height,\n padding,\n paddingHorizontal,\n paddingVertical,\n margin,\n marginTop,\n marginBottom,\n marginLeft,\n marginRight,\n flexDirection,\n flexWrap,\n alignItems,\n justifyContent,\n alignSelf,\n position,\n top,\n bottom,\n left,\n right,\n width,\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n flex,\n flexShrink,\n gap,\n overflow,\n zIndex,\n hoverStyle,\n pressStyle,\n style,\n disabled,\n \"data-testid\": dataTestId,\n testID,\n as,\n src,\n alt,\n ...rest\n}) => {\n const getContainerStyle = (pressed?: boolean): ViewStyle => ({\n backgroundColor:\n pressed && pressStyle?.backgroundColor\n ? pressStyle.backgroundColor\n : backgroundColor,\n borderColor,\n borderWidth,\n borderBottomWidth,\n borderBottomColor,\n borderTopWidth,\n borderTopColor,\n borderLeftWidth,\n borderLeftColor,\n borderRightWidth,\n borderRightColor,\n borderRadius: borderRadius as AnimatableNumericValue,\n borderStyle: borderStyle as ViewStyle[\"borderStyle\"],\n overflow,\n zIndex,\n height: height as DimensionValue,\n width: width as DimensionValue,\n minWidth: minWidth as DimensionValue,\n minHeight: minHeight as DimensionValue,\n maxWidth: maxWidth as DimensionValue,\n maxHeight: maxHeight as DimensionValue,\n padding: padding as DimensionValue,\n paddingHorizontal: paddingHorizontal as DimensionValue,\n paddingVertical: paddingVertical as DimensionValue,\n margin: margin as DimensionValue,\n marginTop: marginTop as DimensionValue,\n marginBottom: marginBottom as DimensionValue,\n marginLeft: marginLeft as DimensionValue,\n marginRight: marginRight as DimensionValue,\n flexDirection,\n flexWrap,\n alignItems,\n justifyContent,\n alignSelf,\n position: position as ViewStyle[\"position\"],\n top: top as DimensionValue,\n bottom: bottom as DimensionValue,\n left: left as DimensionValue,\n right: right as DimensionValue,\n flex,\n flexShrink,\n gap: toGapValue(gap),\n ...(style as ViewStyle),\n });\n\n const finalTestID = dataTestId || testID;\n\n // Map web a11y props; drop the rest of the web-only attributes before\n // spreading onto RN hosts (unknown props warn at runtime).\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const {\n role,\n tabIndex,\n onKeyDown,\n onKeyUp,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": _ariaLabelledBy,\n \"aria-current\": _ariaCurrent,\n \"aria-disabled\": ariaDisabled,\n \"aria-live\": ariaLive,\n \"aria-busy\": ariaBusy,\n className,\n \"data-testid\": _dataTestId,\n cursor: _cursor,\n type: _type,\n ...nativeRest\n } = rest as Record<string, unknown>;\n\n const accessibilityRole =\n (typeof role === \"string\" && roleToAccessibilityRole[role]) ||\n (as === \"button\" ? \"button\" : undefined);\n const isDisabled = Boolean(disabled || ariaDisabled);\n const accessibilityState = {\n disabled: isDisabled || undefined,\n busy: Boolean(ariaBusy) || undefined,\n };\n const accessibilityLiveRegion =\n ariaLive === \"polite\" || ariaLive === \"assertive\" ? ariaLive : undefined;\n\n // Handle as=\"img\" for React Native\n if (as === \"img\" && src) {\n const imageStyle: ImageStyle = {\n width: width as DimensionValue,\n height: height as DimensionValue,\n borderRadius: borderRadius as number,\n position: position as ImageStyle[\"position\"],\n top: top as DimensionValue,\n bottom: bottom as DimensionValue,\n left: left as DimensionValue,\n right: right as DimensionValue,\n ...(style as ImageStyle),\n };\n\n return (\n <Image\n source={{ uri: src }}\n style={imageStyle}\n testID={finalTestID}\n accessibilityLabel={typeof ariaLabel === \"string\" ? ariaLabel : alt}\n resizeMode=\"cover\"\n {...nativeRest}\n />\n );\n }\n\n // Prefer Pressable whenever the node is interactive or explicitly a button,\n // so disabled / aria-disabled controls stay in the a11y tree as buttons.\n if (onPress || as === \"button\") {\n return (\n <Pressable\n onPress={!isDisabled && onPress ? onPress : undefined}\n disabled={isDisabled}\n onLayout={onLayout}\n onMoveShouldSetResponder={onMoveShouldSetResponder}\n onResponderGrant={onResponderGrant}\n onResponderMove={onResponderMove}\n onResponderRelease={onResponderRelease}\n onResponderTerminate={onResponderTerminate}\n style={({ pressed }) => getContainerStyle(pressed)}\n testID={finalTestID}\n accessibilityRole={accessibilityRole}\n accessibilityLabel={\n typeof ariaLabel === \"string\" ? ariaLabel : undefined\n }\n accessibilityState={accessibilityState}\n accessibilityLiveRegion={accessibilityLiveRegion}\n {...nativeRest}\n >\n {children}\n </Pressable>\n );\n }\n\n return (\n <View\n style={getContainerStyle()}\n testID={finalTestID}\n onLayout={onLayout}\n onMoveShouldSetResponder={onMoveShouldSetResponder}\n onResponderGrant={onResponderGrant}\n onResponderMove={onResponderMove}\n onResponderRelease={onResponderRelease}\n onResponderTerminate={onResponderTerminate}\n accessibilityRole={accessibilityRole}\n accessibilityLabel={typeof ariaLabel === \"string\" ? ariaLabel : undefined}\n accessibilityState={accessibilityState}\n accessibilityLiveRegion={accessibilityLiveRegion}\n {...nativeRest}\n >\n {children}\n </View>\n );\n};\n","import React from \"react\";\nimport {\n Text as RNText,\n TextStyle,\n AccessibilityRole,\n StyleSheet,\n} from \"react-native\";\nimport { TextProps } from \"@xsolla/xui-primitives-core\";\n\nconst roleMap: Record<string, AccessibilityRole> = {\n alert: \"alert\",\n heading: \"header\",\n button: \"button\",\n link: \"link\",\n text: \"text\",\n};\n\nconst parseNumericValue = (\n value: string | number | undefined\n): number | undefined => {\n if (value === undefined) return undefined;\n if (typeof value === \"number\") return value;\n const parsed = parseFloat(value);\n return isNaN(parsed) ? undefined : parsed;\n};\n\nexport const Text: React.FC<TextProps> = ({\n children,\n color,\n fontSize,\n fontWeight,\n fontFamily,\n textAlign,\n lineHeight,\n numberOfLines,\n id,\n role,\n testID,\n \"data-testid\": dataTestId,\n style: styleProp,\n ...props\n}) => {\n let resolvedFontFamily = fontFamily\n ? fontFamily.split(\",\")[0].replace(/['\"]/g, \"\").trim()\n : undefined;\n\n if (\n resolvedFontFamily === \"Pilat Wide\" ||\n resolvedFontFamily === \"Pilat Wide Bold\" ||\n resolvedFontFamily === \"Aktiv Grotesk\"\n ) {\n resolvedFontFamily = undefined;\n }\n\n const incomingStyle = StyleSheet.flatten(styleProp) as TextStyle | undefined;\n\n const baseStyle: TextStyle = {\n color: color ?? incomingStyle?.color,\n fontSize: typeof fontSize === \"number\" ? fontSize : undefined,\n fontWeight: fontWeight as TextStyle[\"fontWeight\"],\n fontFamily: resolvedFontFamily,\n textDecorationLine: props.textDecoration as TextStyle[\"textDecorationLine\"],\n textAlign: textAlign ?? incomingStyle?.textAlign,\n lineHeight: parseNumericValue(lineHeight ?? incomingStyle?.lineHeight),\n marginTop: parseNumericValue(\n incomingStyle?.marginTop as number | string | undefined\n ),\n marginBottom: parseNumericValue(\n incomingStyle?.marginBottom as number | string | undefined\n ),\n };\n\n const accessibilityRole = role ? roleMap[role] : undefined;\n\n return (\n <RNText\n style={baseStyle}\n numberOfLines={numberOfLines}\n testID={dataTestId || testID || id}\n accessibilityRole={accessibilityRole}\n >\n {children}\n </RNText>\n );\n};\n","import React from \"react\";\nimport { View, ViewStyle } from \"react-native\";\nimport { IconProps } from \"@xsolla/xui-primitives-core\";\n\nexport const Icon: React.FC<IconProps> = ({\n children,\n color,\n size,\n testID,\n \"data-testid\": dataTestId,\n}) => {\n const style: ViewStyle = {\n width: typeof size === \"number\" ? size : undefined,\n height: typeof size === \"number\" ? size : undefined,\n alignItems: \"center\",\n justifyContent: \"center\",\n };\n\n // On native, we try to pass the color down to children (like Text primitives)\n // to mimic the CSS inheritance behavior of the web version.\n const childrenWithProps = React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return React.cloneElement(child, {\n color: child.props.color || color,\n // Also pass size if child seems to be an icon that needs it\n size: child.props.size || size,\n });\n }\n return child;\n });\n\n return (\n <View style={style} testID={dataTestId || testID}>\n {childrenWithProps}\n </View>\n );\n};\n","export * from \"./Box\";\nexport * from \"./Text\";\nexport * from \"./Spinner\";\nexport * from \"./Icon\";\nexport * from \"./Divider\";\nexport * from \"./Input\";\nexport * from \"./TextArea\";\nexport * from \"./LinearGradient\";\n\nexport const isWeb = false;\nexport const isNative = true;\n","/**\n * Per-size geometry taken from the Figma \"Counter\" component set.\n *\n * `control` is the square box of the − / + buttons; `gap` is the spacing\n * between the three elements. `inputWidth` / `readOnlyWidth` are the full\n * control widths from Figma (buttons + gaps + value). Field height, radius,\n * and font size come from `theme.sizing.input(size)` / `theme.shape.input[size]`\n * because the middle of a `type=\"input\"` Counter is a standard Input.\n */\nexport const COUNTER_SIZE_CONFIG = {\n xl: { control: 28, gap: 10, inputWidth: 149, readOnlyWidth: 100 },\n lg: { control: 24, gap: 10, inputWidth: 142, readOnlyWidth: 90 },\n md: { control: 24, gap: 8, inputWidth: 132, readOnlyWidth: 83 },\n sm: { control: 18, gap: 8, inputWidth: 92, readOnlyWidth: 69 },\n xs: { control: 16, gap: 6, inputWidth: 82, readOnlyWidth: 59 },\n} as const;\n\n/**\n * Rounds `value` into `[min, max]`. A value above the maximum is rounded down\n * to the maximum, and a value below the minimum is rounded up to the minimum.\n * Missing bounds are unbounded on that side.\n */\nexport const clampToRange = (\n value: number,\n min?: number,\n max?: number\n): number => {\n let next = value;\n if (typeof min === \"number\" && next < min) next = min;\n if (typeof max === \"number\" && next > max) next = max;\n return next;\n};\n\n/**\n * Strips everything that cannot be part of an integer from typed input.\n * Non-numeric characters are rejected silently rather than flagged — Counter\n * has no error state. A single leading `-` survives only when negatives are\n * allowed.\n */\nexport const sanitizeCounterInput = (\n raw: string,\n allowNegative: boolean\n): string => {\n const digitsAndSigns = raw.replace(/[^\\d-]/g, \"\");\n const digits = digitsAndSigns.replace(/-/g, \"\");\n if (allowNegative && digitsAndSigns.startsWith(\"-\")) {\n return `-${digits}`;\n }\n return digits;\n};\n\n/**\n * Parses committed text into a number. Returns `null` for an empty field or a\n * lone `-`, which the caller resolves by restoring the previous value.\n */\nexport const parseCounterValue = (raw: string): number | null => {\n const trimmed = raw.trim();\n if (trimmed === \"\" || trimmed === \"-\") return null;\n const parsed = Number.parseInt(trimmed, 10);\n return Number.isNaN(parsed) ? null : parsed;\n};\n\n/**\n * True when the range allows values below zero, which is what decides whether\n * a typed `-` is kept.\n */\nexport const allowsNegative = (min?: number): boolean =>\n typeof min !== \"number\" || min < 0;\n"],"mappings":";AAAA,OAAOA,UAAS,YAAY,QAAQ,gBAAgB;;;ACCpD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AAsMD;AAnMN,IAAM,0BAA6D;AAAA,EACjE,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,cAAc;AAAA,EACd,aAAa;AAAA,EACb,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AACT;AAGA,IAAM,aAAa,CAAC,QAAyD;AAC3E,MAAI,QAAQ,OAAW,QAAO;AAC9B,MAAI,O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Y,UAAU;AAAA,QACvC,iBAAe,YAAY;AAAA,QAC3B,eAAa;AAAA,QAEZ;AAAA;AAAA,UACD;AAAA,YAAC;AAAA;AAAA,cACC,eAAc;AAAA,cACd,YAAW;AAAA,cACX,KAAK,WAAW;AAAA,cAChB,OAAO,WAAW;AAAA,cAEjB;AAAA;AAAA,gBACD,gBAAAA,KAAC,OAAI,MAAM,GAAG,UAAU,GACtB,0BAAAA;AAAA,kBAAC;AAAA;AAAA,oBACC,KAAK;AAAA,oBACL,IAAI;AAAA,oBACJ;AAAA,oBACA;AAAA,oBACA,OAAO;AAAA,oBACP;AAAA,oBACA,UAAU;AAAA,oBACV,QAAQ;AAAA,oBACR,WAAW;AAAA,oBAGX,MAAK;AAAA,oBACL,WAAU;AAAA,oBACV,MAAK;AAAA,oBACL,iBAAe,kBAAkB;AAAA,oBACjC,iBAAe;AAAA,oBACf,iBAAe;AAAA,oBACf,cAAY,YAAY,SAAY;AAAA,oBACnC,GAAI,YAAY,EAAE,mBAAmB,QAAQ,IAAI,CAAC;AAAA,oBAEnD,OAAO,EAAE,WAAW,SAAS;AAAA,oBAC7B;AAAA,oBACA;AAAA,oBACA,QAAQ,SAAS,GAAG,MAAM,YAAY;AAAA;AAAA,gBACxC,GACF;AAAA,gBACC;AAAA;AAAA;AAAA,UACH;AAAA;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,QAAQ,cAAc;","names":["React","jsx","View","jsx","jsx","React"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xsolla/xui-counter",
|
|
3
|
+
"version": "0.200.0",
|
|
4
|
+
"main": "./web/index.js",
|
|
5
|
+
"module": "./web/index.mjs",
|
|
6
|
+
"types": "./web/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "yarn build:web && yarn build:native",
|
|
9
|
+
"build:web": "PLATFORM=web tsup",
|
|
10
|
+
"build:native": "PLATFORM=native tsup",
|
|
11
|
+
"test": "vitest",
|
|
12
|
+
"test:run": "vitest run",
|
|
13
|
+
"test:coverage": "vitest run --coverage"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@xsolla/xui-core": "0.200.0",
|
|
17
|
+
"@xsolla/xui-icons-base": "0.200.0",
|
|
18
|
+
"@xsolla/xui-input": "0.200.0",
|
|
19
|
+
"@xsolla/xui-primitives-core": "0.200.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=16.8.0",
|
|
23
|
+
"styled-components": ">=4"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
27
|
+
"@testing-library/react": "^14.1.2",
|
|
28
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
29
|
+
"jsdom": "^24.0.0",
|
|
30
|
+
"react": "^18.0.0",
|
|
31
|
+
"react-dom": "^18.0.0",
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"vitest": "^4.0.18"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"react-native": "./native/index.js",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"react-native": {
|
|
41
|
+
"types": "./native/index.d.ts",
|
|
42
|
+
"import": "./native/index.mjs",
|
|
43
|
+
"require": "./native/index.js"
|
|
44
|
+
},
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./web/index.d.ts",
|
|
47
|
+
"default": "./web/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./web/index.d.ts",
|
|
51
|
+
"default": "./web/index.js"
|
|
52
|
+
},
|
|
53
|
+
"default": {
|
|
54
|
+
"types": "./web/index.d.ts",
|
|
55
|
+
"default": "./web/index.js"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
package/web/index.d.mts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ThemeOverrideProps, ComponentSize } from '@xsolla/xui-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How the Counter renders the value between the − and + buttons.
|
|
6
|
+
*
|
|
7
|
+
* - `"input"` — an editable text field. Supports Hover and Focus because it is
|
|
8
|
+
* a real input target.
|
|
9
|
+
* - `"readOnly"` — plain text changed only by the buttons. Has no Hover or
|
|
10
|
+
* Focus state of its own; the buttons carry their own hover states.
|
|
11
|
+
*
|
|
12
|
+
* `"readOnly"` renders the value as plain text, **not** as a disabled or
|
|
13
|
+
* `readonly` input — both would tell assistive technology the value cannot
|
|
14
|
+
* change, which is false.
|
|
15
|
+
*/
|
|
16
|
+
type CounterType = "input" | "readOnly";
|
|
17
|
+
interface CounterProps extends ThemeOverrideProps {
|
|
18
|
+
/**
|
|
19
|
+
* Current value (controlled). Pass `null` for a genuinely empty counter —
|
|
20
|
+
* the Figma `Filled=False` state. An empty counter is unusual; most counters
|
|
21
|
+
* start at a defined value such as `0` or `1`.
|
|
22
|
+
*/
|
|
23
|
+
value?: number | null;
|
|
24
|
+
/**
|
|
25
|
+
* Initial value when the component is uncontrolled. Ignored when `value` is
|
|
26
|
+
* provided.
|
|
27
|
+
*
|
|
28
|
+
* @default null
|
|
29
|
+
*/
|
|
30
|
+
defaultValue?: number | null;
|
|
31
|
+
/**
|
|
32
|
+
* Fired when the value is committed — on button press, on blur, or on Enter.
|
|
33
|
+
* Never fired on every keystroke, and never fired with an out-of-range or
|
|
34
|
+
* empty value: the committed number is always clamped into
|
|
35
|
+
* `[min, max]`.
|
|
36
|
+
*/
|
|
37
|
+
onChange?: (value: number) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Lowest allowed value. When reached, the − button becomes unavailable.
|
|
40
|
+
* Values below it are rounded up to it on commit.
|
|
41
|
+
*/
|
|
42
|
+
min?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Highest allowed value. When reached, the + button becomes unavailable.
|
|
45
|
+
* Values above it are rounded down to it on commit.
|
|
46
|
+
*/
|
|
47
|
+
max?: number;
|
|
48
|
+
/**
|
|
49
|
+
* How much one − / + press changes the value by. Define a larger step when
|
|
50
|
+
* the domain requires it (for example steps of 5 for bulk items).
|
|
51
|
+
*
|
|
52
|
+
* @default 1
|
|
53
|
+
*/
|
|
54
|
+
step?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Size of the counter. Drives the button box, the field height, the type
|
|
57
|
+
* scale, and the gap between the three elements.
|
|
58
|
+
*
|
|
59
|
+
* @default "md"
|
|
60
|
+
*/
|
|
61
|
+
size?: ComponentSize;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the value is an editable field (`"input"`) or plain text driven
|
|
64
|
+
* only by the buttons (`"readOnly"`).
|
|
65
|
+
*
|
|
66
|
+
* @default "input"
|
|
67
|
+
*/
|
|
68
|
+
type?: CounterType;
|
|
69
|
+
/**
|
|
70
|
+
* Disables the whole control — both buttons and, for `type="input"`, the
|
|
71
|
+
* field. The current value stays visible; always explain nearby why the
|
|
72
|
+
* quantity cannot be changed if the reason is not obvious.
|
|
73
|
+
*
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
disabled?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Visible label rendered above the whole control (buttons + value), not
|
|
79
|
+
* between the buttons. Prefer FieldGroup or adjacent text in product UI;
|
|
80
|
+
* this prop is a convenience for the same layout. `type="input"` only —
|
|
81
|
+
* use `aria-label` for `type="readOnly"`. The − / + buttons alone do not
|
|
82
|
+
* name what is being counted.
|
|
83
|
+
*/
|
|
84
|
+
label?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Accessible name for the control when no visible `label` is present, e.g.
|
|
87
|
+
* `"Quantity"`, `"Number of guests"`, `"Quantity of Dragon Scale skin"`.
|
|
88
|
+
*/
|
|
89
|
+
"aria-label"?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Accessible name for the decrement button. Include the subject where
|
|
92
|
+
* possible so multiple counters on one page stay distinguishable.
|
|
93
|
+
*
|
|
94
|
+
* @default "Decrease quantity"
|
|
95
|
+
*/
|
|
96
|
+
decrementLabel?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Accessible name for the increment button.
|
|
99
|
+
*
|
|
100
|
+
* @default "Increase quantity"
|
|
101
|
+
*/
|
|
102
|
+
incrementLabel?: string;
|
|
103
|
+
/**
|
|
104
|
+
* `name` attribute forwarded to the underlying field. Only used for
|
|
105
|
+
* `type="input"`.
|
|
106
|
+
*/
|
|
107
|
+
name?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Unique identifier for the field element. Used for accessibility linking.
|
|
110
|
+
*/
|
|
111
|
+
id?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Test ID for testing frameworks. On web this renders as `data-testid`; on
|
|
114
|
+
* React Native it renders as `testID`. Sub-elements append `__decrement`,
|
|
115
|
+
* `__increment`, `__input`, and `__value`.
|
|
116
|
+
*/
|
|
117
|
+
testID?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A numeric stepper that lets the user increase or decrease a value using
|
|
122
|
+
* dedicated − and + buttons.
|
|
123
|
+
*
|
|
124
|
+
* Counter has no error state: values outside the allowed range are never
|
|
125
|
+
* rejected, they are silently clamped to the nearest bound on commit, so the
|
|
126
|
+
* component is always in a valid state.
|
|
127
|
+
*/
|
|
128
|
+
declare const Counter: React.ForwardRefExoticComponent<CounterProps & React.RefAttributes<HTMLInputElement>>;
|
|
129
|
+
|
|
130
|
+
export { Counter, type CounterProps, type CounterType };
|
package/web/index.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ThemeOverrideProps, ComponentSize } from '@xsolla/xui-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How the Counter renders the value between the − and + buttons.
|
|
6
|
+
*
|
|
7
|
+
* - `"input"` — an editable text field. Supports Hover and Focus because it is
|
|
8
|
+
* a real input target.
|
|
9
|
+
* - `"readOnly"` — plain text changed only by the buttons. Has no Hover or
|
|
10
|
+
* Focus state of its own; the buttons carry their own hover states.
|
|
11
|
+
*
|
|
12
|
+
* `"readOnly"` renders the value as plain text, **not** as a disabled or
|
|
13
|
+
* `readonly` input — both would tell assistive technology the value cannot
|
|
14
|
+
* change, which is false.
|
|
15
|
+
*/
|
|
16
|
+
type CounterType = "input" | "readOnly";
|
|
17
|
+
interface CounterProps extends ThemeOverrideProps {
|
|
18
|
+
/**
|
|
19
|
+
* Current value (controlled). Pass `null` for a genuinely empty counter —
|
|
20
|
+
* the Figma `Filled=False` state. An empty counter is unusual; most counters
|
|
21
|
+
* start at a defined value such as `0` or `1`.
|
|
22
|
+
*/
|
|
23
|
+
value?: number | null;
|
|
24
|
+
/**
|
|
25
|
+
* Initial value when the component is uncontrolled. Ignored when `value` is
|
|
26
|
+
* provided.
|
|
27
|
+
*
|
|
28
|
+
* @default null
|
|
29
|
+
*/
|
|
30
|
+
defaultValue?: number | null;
|
|
31
|
+
/**
|
|
32
|
+
* Fired when the value is committed — on button press, on blur, or on Enter.
|
|
33
|
+
* Never fired on every keystroke, and never fired with an out-of-range or
|
|
34
|
+
* empty value: the committed number is always clamped into
|
|
35
|
+
* `[min, max]`.
|
|
36
|
+
*/
|
|
37
|
+
onChange?: (value: number) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Lowest allowed value. When reached, the − button becomes unavailable.
|
|
40
|
+
* Values below it are rounded up to it on commit.
|
|
41
|
+
*/
|
|
42
|
+
min?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Highest allowed value. When reached, the + button becomes unavailable.
|
|
45
|
+
* Values above it are rounded down to it on commit.
|
|
46
|
+
*/
|
|
47
|
+
max?: number;
|
|
48
|
+
/**
|
|
49
|
+
* How much one − / + press changes the value by. Define a larger step when
|
|
50
|
+
* the domain requires it (for example steps of 5 for bulk items).
|
|
51
|
+
*
|
|
52
|
+
* @default 1
|
|
53
|
+
*/
|
|
54
|
+
step?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Size of the counter. Drives the button box, the field height, the type
|
|
57
|
+
* scale, and the gap between the three elements.
|
|
58
|
+
*
|
|
59
|
+
* @default "md"
|
|
60
|
+
*/
|
|
61
|
+
size?: ComponentSize;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the value is an editable field (`"input"`) or plain text driven
|
|
64
|
+
* only by the buttons (`"readOnly"`).
|
|
65
|
+
*
|
|
66
|
+
* @default "input"
|
|
67
|
+
*/
|
|
68
|
+
type?: CounterType;
|
|
69
|
+
/**
|
|
70
|
+
* Disables the whole control — both buttons and, for `type="input"`, the
|
|
71
|
+
* field. The current value stays visible; always explain nearby why the
|
|
72
|
+
* quantity cannot be changed if the reason is not obvious.
|
|
73
|
+
*
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
disabled?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Visible label rendered above the whole control (buttons + value), not
|
|
79
|
+
* between the buttons. Prefer FieldGroup or adjacent text in product UI;
|
|
80
|
+
* this prop is a convenience for the same layout. `type="input"` only —
|
|
81
|
+
* use `aria-label` for `type="readOnly"`. The − / + buttons alone do not
|
|
82
|
+
* name what is being counted.
|
|
83
|
+
*/
|
|
84
|
+
label?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Accessible name for the control when no visible `label` is present, e.g.
|
|
87
|
+
* `"Quantity"`, `"Number of guests"`, `"Quantity of Dragon Scale skin"`.
|
|
88
|
+
*/
|
|
89
|
+
"aria-label"?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Accessible name for the decrement button. Include the subject where
|
|
92
|
+
* possible so multiple counters on one page stay distinguishable.
|
|
93
|
+
*
|
|
94
|
+
* @default "Decrease quantity"
|
|
95
|
+
*/
|
|
96
|
+
decrementLabel?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Accessible name for the increment button.
|
|
99
|
+
*
|
|
100
|
+
* @default "Increase quantity"
|
|
101
|
+
*/
|
|
102
|
+
incrementLabel?: string;
|
|
103
|
+
/**
|
|
104
|
+
* `name` attribute forwarded to the underlying field. Only used for
|
|
105
|
+
* `type="input"`.
|
|
106
|
+
*/
|
|
107
|
+
name?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Unique identifier for the field element. Used for accessibility linking.
|
|
110
|
+
*/
|
|
111
|
+
id?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Test ID for testing frameworks. On web this renders as `data-testid`; on
|
|
114
|
+
* React Native it renders as `testID`. Sub-elements append `__decrement`,
|
|
115
|
+
* `__increment`, `__input`, and `__value`.
|
|
116
|
+
*/
|
|
117
|
+
testID?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A numeric stepper that lets the user increase or decrease a value using
|
|
122
|
+
* dedicated − and + buttons.
|
|
123
|
+
*
|
|
124
|
+
* Counter has no error state: values outside the allowed range are never
|
|
125
|
+
* rejected, they are silently clamped to the nearest bound on commit, so the
|
|
126
|
+
* component is always in a valid state.
|
|
127
|
+
*/
|
|
128
|
+
declare const Counter: React.ForwardRefExoticComponent<CounterProps & React.RefAttributes<HTMLInputElement>>;
|
|
129
|
+
|
|
130
|
+
export { Counter, type CounterProps, type CounterType };
|