1.0.5 • Published 1 year ago

sb-framer-counter v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

📖 Table of Contents

🚀 Getting Started

🐇 Jump Start

With NPM:

npm i sb-framer-counter

With Yarn:

yarn add sb-framer-counter
import { useState } from "react";
import { FramerCounter } from "sb-framer-counter";

function Example() {
	const [value, setValue] = useState(10);
	return (
		<FramerCounter
			minimumValue={10}
			maximumValue={100}
			stepValue={10}
			initialValue={0}
			size="md"
			inactiveTrackColor="#fed7aa"
			activeTrackColor="#fddec0"
			activeButtonColor="#ffedd5"
			inactiveIconColor="#fb923c"
			hoverIconColor="#ea580c"
			activeIconColor="#9a3412"
			disabledIconColor="#fdba74"
			thumbColor="#f97316"
			thumbShadowAnimationOnTrackHoverEnabled={false}
			focusRingColor="#fff7ed"
			onChange={(value) => {
				setValue(value);
			}}
		/>
	);
}

💻 Live Demo

Open in CodeSandbox

⚙️ Configuration

FramerCounter supports the following props:

PropTypeDefault valueDescription
minimumValuenumber0The minimum value.
maximumValuenumberNumber.MAX_SAFE_INTEGERThe maximum value.
stepValuenumber1The step increment value.
initialValuenumberminimumValueThe initial value.
onChangeFunctionundefinedThe callback invoked when the value changes.
sizestringsmThe size of the numeric counter. There are 4 available sizes:xs — 92.5x37pxsm — 185x74pxmd — 277.5x111pxlg — 370x148px
inactiveTrackColorstring#2b2b2bThe color of the track while the thumb is not being horizontally dragged.
activeTrackColorstring#1f1f1fThe color of the track while the thumb is being horizontally dragged and is at the maximum trackable distance from the track's center.
hoverButtonColorstringtransparentThe color of the decrement/increment button in a hover state.
activeButtonColorstring#ecececThe color of the decrement/increment button in an active state.
inactiveIconColorstring#858585The color of the decrement/increment button icon in an inactive state.
hoverIconColorstring#ffffffThe color of the decrement/increment button icon in a hover state.
activeIconColorstring#000000The color of the decrement/increment button icon in an active state.
disabledIconColorstring#383838The color of the decrement/increment button icon in a disabled state.
thumbColorstring#444444The color of the thumb.
thumbLabelColorstring#ffffffThe color of the thumb's label.
thumbShadowAnimationOnTrackHoverEnabledbooleantrueIf true, the thumb's shadow will animate when hovering over the track.
focusRingColorstring#ecececThe color of the focus ring of the interactive elements.

In order to customise the thumb's font settings, we can use CSS, like so:

[data-testid="framer-counter-thumb"] {
	font-family: "Times New Roman", Times, serif;
	font-style: italic;
	font-weight: 800;
}

♿️ Accessibility

In order to comply with the web accessibility standards, we must make use of the decrementButtonAriaLabel and incrementButtonAriaLabel props, like so:

function AccessibleExample() {
	return <FramerCounter decrementButtonAriaLabel="Decrement" incrementButtonAriaLabel="Increment" />;
}

Also, we can use a thumbAriaLabel prop to provide a description for the value rendered inside a thumb, like so:

function EnhancedThumbAccessibilityExample() {
	const [value, setValue] = useState(0);
	return (
		<FramerCounter
			thumbAriaLabel={`${value} items`}
			onChange={(value) => {
				setValue(value);
			}}
		/>
	);
}

👨🏼‍⚖️ License

MIT

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago