@@ -4,7 +4,6 @@ import { DeepPartial } from 'ts-essentials';
44
55import { useTheme } from '../../theme' ;
66import { mergeStyles , ReplaceReturnType } from '../../utils/mergeStyles' ;
7- import { Box } from '../Box' ;
87import { Icon } from '../Icon' ;
98import { Text } from '../Typography' ;
109import {
@@ -14,13 +13,24 @@ import {
1413} from './Counter.styles' ;
1514
1615export interface CounterProps {
17- count : number ;
16+ /** Count to be displayed. */
17+ count ?: number ;
18+
19+ /** Minimum count for the counter. Upon reaching the limit, it will disable decrement button. */
1820 min ?: number ;
21+
22+ /** Maximum count for the counter. Upon reaching the limit, it will disable increment button. */
1923 max ?: number ;
20- /* custom component in place of count */
24+
25+ /** Custom component in place of count */
2126 component ?: React . ReactNode ;
27+
28+ /** Called when increment button is pressed */
2229 onIncrement ?: ( ) => void ;
30+
31+ /** Called when decrement button is pressed */
2332 onDecrement ?: ( ) => void ;
33+
2434 /**
2535 * Inline styles for components
2636 */
@@ -29,7 +39,7 @@ export interface CounterProps {
2939
3040export const Counter = ( props : CounterProps ) => {
3141 const {
32- count,
42+ count = 0 ,
3343 component,
3444 max,
3545 min,
@@ -44,22 +54,23 @@ export const Counter = (props: CounterProps) => {
4454 containerStyle,
4555 counterStyle,
4656 countStyle,
47- textStyle ,
57+ decrementWrapperStyle ,
4858 disabledStyle,
59+ incrementWrapperStyle,
60+ textStyle,
4961 } = mergeStyles (
5062 getCounterStyles ,
5163 getStyles ,
5264 theme . components . getCounterStyles ,
53- ) ( { } , theme ) ;
65+ ) ( { count } , theme ) ;
5466
5567 const isDecrementDisabled = min === count ;
5668 const isIncrementDisabled = max === count ;
5769
5870 return (
5971 < View style = { containerStyle } >
60- < Box paddingRight = { 16 } >
72+ < View style = { decrementWrapperStyle } >
6173 < TouchableOpacity
62- activeOpacity = { 0.7 }
6374 style = { {
6475 ...counterStyle ,
6576 ...( isDecrementDisabled && disabledStyle ) ,
@@ -77,7 +88,7 @@ export const Counter = (props: CounterProps) => {
7788 }
7889 />
7990 </ TouchableOpacity >
80- </ Box >
91+ </ View >
8192 { component || (
8293 < View style = { countStyle } >
8394 < Text
@@ -86,9 +97,8 @@ export const Counter = (props: CounterProps) => {
8697 > { `${ count } ` } </ Text >
8798 </ View >
8899 ) }
89- < Box paddingLeft = { 16 } >
100+ < View style = { incrementWrapperStyle } >
90101 < TouchableOpacity
91- activeOpacity = { 0.7 }
92102 style = { {
93103 ...counterStyle ,
94104 ...( isIncrementDisabled && disabledStyle ) ,
@@ -106,7 +116,7 @@ export const Counter = (props: CounterProps) => {
106116 }
107117 />
108118 </ TouchableOpacity >
109- </ Box >
119+ </ View >
110120 </ View >
111121 ) ;
112122} ;
0 commit comments