Skip to content

Commit

Permalink
fix(number-field): remove zagjs and use react-aria (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyyaaa authored Oct 30, 2023
1 parent dd9a246 commit 75a3254
Show file tree
Hide file tree
Showing 36 changed files with 573 additions and 464 deletions.
8 changes: 4 additions & 4 deletions compiler/scaffold.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ module.exports = {
path: "../change-chain-combobox",
},
},
"number-input": {
"number-field": {
jsxMap: {
ScaffoldNumberInput: "NumberInput",
ScaffoldNumberField: "NumberField",
},
import: {
imports: { NumberInput: "default" },
path: "../number-input",
imports: { NumberField: "default" },
path: "../number-field",
},
},
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"@formkit/auto-animate": "1.0.0-beta.6",
"@parcel/packager-ts": "^2.10.0",
"@parcel/watcher": "^2.3.0",
"@react-aria/i18n": "^3.8.4",
"@react-aria/numberfield": "^3.9.1",
"@react-aria/utils": "^3.21.1",
"@react-stately/numberfield": "^3.6.2",
"@swc/helpers": "^0.5.0",
"@types/animejs": "^3.1.7",
"@types/node": "^20.5.8",
Expand All @@ -52,9 +56,6 @@
"@vanilla-extract/dynamic": "^2.0.3",
"@vitejs/plugin-vue": "^4.1.0",
"@vue/babel-preset-app": "^5.0.8",
"@zag-js/number-input": "^0.26.0",
"@zag-js/react": "^0.26.0",
"@zag-js/vue": "^0.26.0",
"autoprefixer": "^10.4.14",
"command-line-args": "^5.2.1",
"copy-to-clipboard": "^3.3.3",
Expand Down
33 changes: 30 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,33 @@
"import": "./dist/index.d.ts",
"default": "./dist/index.d.ts"
},
"development": {
"worker": {
"module": "./dist/interchain-ui-kit-react.development.worker.esm.js",
"import": "./dist/interchain-ui-kit-react.development.worker.cjs.mjs",
"default": "./dist/interchain-ui-kit-react.development.worker.cjs.js"
},
"browser": {
"module": "./dist/interchain-ui-kit-react.browser.development.esm.js",
"import": "./dist/interchain-ui-kit-react.browser.development.cjs.mjs",
"default": "./dist/interchain-ui-kit-react.browser.development.cjs.js"
},
"module": "./dist/interchain-ui-kit-react.development.esm.js",
"import": "./dist/interchain-ui-kit-react.development.cjs.mjs",
"default": "./dist/interchain-ui-kit-react.development.cjs.js"
},
"worker": {
"module": "./dist/interchain-ui-kit-react.worker.esm.js",
"import": "./dist/interchain-ui-kit-react.worker.cjs.mjs",
"default": "./dist/interchain-ui-kit-react.worker.cjs.js"
},
"browser": {
"module": "./dist/interchain-ui-kit-react.browser.esm.js",
"import": "./dist/interchain-ui-kit-react.browser.cjs.mjs",
"default": "./dist/interchain-ui-kit-react.browser.cjs.js"
},
"module": "./dist/interchain-ui-kit-react.esm.js",
"import": "./dist/interchain-ui-kit-react.esm.js",
"import": "./dist/interchain-ui-kit-react.cjs.mjs",
"default": "./dist/interchain-ui-kit-react.cjs.js"
},
"./styles": "./dist/interchain-ui-kit-react.cjs.css",
Expand Down Expand Up @@ -46,12 +71,14 @@
"@floating-ui/dom": "^1.5.2",
"@floating-ui/react": "^0.26.0",
"@formkit/auto-animate": "1.0.0-beta.6",
"@react-aria/i18n": "^3.8.4",
"@react-aria/numberfield": "^3.9.1",
"@react-aria/utils": "^3.21.1",
"@react-stately/numberfield": "^3.6.2",
"@vanilla-extract/css": "^1.12.0",
"@vanilla-extract/css-utils": "^0.1.3",
"@vanilla-extract/dynamic": "^2.0.3",
"@vanilla-extract/recipes": "^0.4.0",
"@zag-js/number-input": "^0.26.0",
"@zag-js/react": "^0.26.0",
"animejs": "^3.2.1",
"bignumber.js": "^9.1.1",
"clsx": "^1.2.1",
Expand Down
1 change: 1 addition & 0 deletions packages/react/scaffolds/number-field/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./number-field";
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export const borderless = style({
},
});

export const withStartAddon = style({
export const withDecrementButton = style({
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
});

export const withEndAddon = style({
export const withIncrementButton = style({
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
});
107 changes: 107 additions & 0 deletions packages/react/scaffolds/number-field/number-field.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { useState, useId, forwardRef } from "react";
import { useNumberFieldState } from "@react-stately/numberfield";
import { useNumberField } from "@react-aria/numberfield";
import { useLocale } from "@react-aria/i18n";
import { mergeRefs } from "@react-aria/utils";

import clx from "clsx";
import {
inputStyles,
inputSizes,
inputIntent,
inputRootIntent,
rootInput,
rootInputFocused,
} from "@/ui/text-field/text-field.css";
import FieldLabel from "@/ui/field-label";
import Stack from "@/ui/stack";
import Box from "@/ui/box";
import useTheme from "../hooks/use-theme";
import * as styles from "./number-field.css";
import type { NumberInputProps } from "./number-field.types";

const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
(props, forwardedRef) => {
const {
id = useId(),
label,
isDisabled,
size = "sm",
intent = "default",
} = props;

const { theme } = useTheme();
const { locale } = useLocale();
const [isFocused, setIsFocused] = useState<boolean>(false);

const state = useNumberFieldState({
...props,
locale,
onFocusChange(focused) {
setIsFocused(focused);
},
});

const inputRef = React.useRef(null);
const handleRef = mergeRefs(inputRef, forwardedRef);

const {
labelProps,
groupProps,
inputProps,
incrementButtonProps,
decrementButtonProps,
} = useNumberField(props, state, inputRef);

return (
<Box className={props?.className}>
<Stack direction="vertical" space="$4">
{label && <FieldLabel htmlFor={id} label={label} {...labelProps} />}

<div
{...groupProps}
className={clx(
rootInput,
isFocused ? rootInputFocused : null,
props.isDisabled
? inputRootIntent.disabled
: inputRootIntent[props.intent],
props.inputContainer
)}
>
{props.canDecrement && React.isValidElement(props.decrementButton)
? React.cloneElement(props.decrementButton, decrementButtonProps)
: props?.decrementButton}

<Box
as="input"
attributes={inputProps}
ref={handleRef}
textAlign={props.textAlign}
fontSize={props.fontSize}
className={clx(
inputStyles[theme],
inputSizes[size],
props.isDisabled ? inputIntent.disabled : inputIntent[intent],
props.inputClassName,
props.borderless && styles.borderless,
isDisabled && props.decrementButton
? styles.withDecrementButton
: null,
isDisabled && props.incrementButton
? styles.withIncrementButton
: null
)}
/>

{props.canIncrement && React.isValidElement(props.incrementButton)
? React.cloneElement(props.incrementButton, incrementButtonProps)
: props?.incrementButton}
</div>
</Stack>
</Box>
);
}
);

export default NumberInput;
39 changes: 39 additions & 0 deletions packages/react/scaffolds/number-field/number-field.types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ReactNode } from "react";
import type { Sprinkles } from "@/styles/rainbow-sprinkles.css";
import type { AriaNumberFieldProps } from "@react-aria/numberfield";

export interface NumberInputProps {
// ==== Core logic props
defaultValue?: number;
value?: number;
minValue?: number;
maxValue?: number;
incrementButton?: ReactNode;
decrementButton?: ReactNode;
canIncrement?: boolean;
canDecrement?: boolean;
// ==== Form field props
id?: string;
isDisabled?: boolean;
isReadOnly?: boolean;
autoFocus?: boolean;
formatOptions?: AriaNumberFieldProps["formatOptions"];
name?: string;
label?: string;
onChange?: (value: number) => void;
onBlur?: (e?: any) => void;
onFocus?: (e?: any) => void;
onFocusChange?: (isFocused: boolean) => void;
onKeyDown?: (e?: any) => void;
onKeyUp?: (e?: any) => void;
// ==== Style props
textAlign?: Sprinkles["textAlign"];
fontSize?: Sprinkles["fontSize"];
size?: "sm" | "md";
placeholder?: string | undefined;
intent?: "default" | "error";
className?: string;
inputContainer?: string;
inputClassName?: string;
borderless?: boolean;
}
1 change: 0 additions & 1 deletion packages/react/scaffolds/number-input/index.ts

This file was deleted.

116 changes: 0 additions & 116 deletions packages/react/scaffolds/number-input/number-input.tsx

This file was deleted.

Loading

0 comments on commit 75a3254

Please sign in to comment.