pebble-web 2.2.7 → 2.3.2

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.
@@ -4,6 +4,8 @@ export { colors } from 'pebble-shared';
4
4
  import React__default, { createElement, Fragment, PureComponent, Children, cloneElement, createRef, createContext, Component } from 'react';
5
5
  import Ink from 'react-ink';
6
6
  import RCalendar from 'react-calendar/dist/Calendar';
7
+ import subDays from 'date-fns/subDays';
8
+ import addDays from 'date-fns/addDays';
7
9
  import startOfDay from 'date-fns/startOfDay';
8
10
  import endOfDay from 'date-fns/endOfDay';
9
11
  import isSameDay from 'date-fns/isSameDay';
@@ -633,14 +635,16 @@ class Calendar extends PureComponent {
633
635
  if (Array.isArray(value) && value.length === 2) {
634
636
  this.setState({
635
637
  value: value,
636
- singleSelectedDate: null
638
+ singleSelectedDate: null,
639
+ maxRangeDates: undefined
637
640
  }, () => props.onChange(value));
638
641
  }
639
642
  } else {
640
643
  if (!Array.isArray(value)) {
641
644
  this.setState({
642
645
  value,
643
- singleSelectedDate: null
646
+ singleSelectedDate: null,
647
+ maxRangeDates: undefined
644
648
  }, () => props.onChange(value));
645
649
  }
646
650
  }
@@ -649,6 +653,17 @@ class Calendar extends PureComponent {
649
653
  const {
650
654
  onClickDay
651
655
  } = this.props;
656
+ if (this.props.range && this.props.maxRange) {
657
+ const {
658
+ maxRange
659
+ } = this.props;
660
+ this.setState({
661
+ maxRangeDates: {
662
+ future: addDays(day, maxRange),
663
+ past: subDays(day, maxRange)
664
+ }
665
+ });
666
+ }
652
667
  this.setState({
653
668
  singleSelectedDate: [startOfDay(day), endOfDay(day)]
654
669
  });
@@ -716,8 +731,13 @@ class Calendar extends PureComponent {
716
731
  className,
717
732
  onApply,
718
733
  onClear,
734
+ maxDate,
735
+ minDate,
719
736
  ...rest
720
737
  } = this.props;
738
+ const {
739
+ maxRangeDates
740
+ } = this.state;
721
741
  return /*#__PURE__*/createElement("div", {
722
742
  className: cx(wrapperStyle, {
723
743
  [/*#__PURE__*/css( {
@@ -749,7 +769,9 @@ class Calendar extends PureComponent {
749
769
  fontSize: 14
750
770
  },
751
771
  className: "pi pi-arrow-right"
752
- })
772
+ }),
773
+ maxDate: maxDate || maxRangeDates && maxRangeDates.future,
774
+ minDate: minDate || maxRangeDates && maxRangeDates.past
753
775
  })), (onClear || onApply) && /*#__PURE__*/createElement("div", {
754
776
  className: buttonsWrapper
755
777
  }, onClear && /*#__PURE__*/createElement(Button, {
@@ -1945,7 +1967,8 @@ class Search extends PureComponent {
1945
1967
  showSearchIcon,
1946
1968
  className,
1947
1969
  clearable,
1948
- value
1970
+ value,
1971
+ loading
1949
1972
  } = this.props;
1950
1973
  const wrapperClassName = cx(searchWrapperStyle, {
1951
1974
  __pebble__search__small: type === "small",
@@ -1966,7 +1989,10 @@ class Search extends PureComponent {
1966
1989
  },
1967
1990
  ref: this.searchInputRef,
1968
1991
  value: value
1969
- }, inputProps)), clearable && /*#__PURE__*/createElement("div", {
1992
+ }, inputProps)), loading && /*#__PURE__*/createElement(Loader, {
1993
+ scale: 0.4,
1994
+ color: colors.violet.base
1995
+ }), clearable && /*#__PURE__*/createElement("div", {
1970
1996
  className: cx(clearContainer, {
1971
1997
  __display: !!value && !!value.length
1972
1998
  }),
@@ -2887,6 +2913,95 @@ class RadioGroup extends PureComponent {
2887
2913
  }
2888
2914
  }
2889
2915
 
2916
+ const wrapStyle = /*#__PURE__*/css({ ...flexRow,
2917
+ cursor: "pointer"
2918
+ }, ";label:wrapStyle;" + ( "" ));
2919
+ const disabledStyle = /*#__PURE__*/css( {
2920
+ name: "pl7a4e-disabledStyle",
2921
+ styles: "cursor:not-allowed;;label:disabledStyle;"
2922
+ } );
2923
+ const unSelectedStar = /*#__PURE__*/css({
2924
+ marginLeft: "2px",
2925
+ color: colors.gray.border,
2926
+ fontSize: "20px"
2927
+ }, ";label:unSelectedStar;" + ( "" ));
2928
+ const selectedStar = /*#__PURE__*/css({
2929
+ color: colors.yellow.base
2930
+ }, ";label:selectedStar;" + ( "" ));
2931
+
2932
+ function generateStars(maxRating, selectedValue) {
2933
+ return Array.from({
2934
+ length: maxRating
2935
+ }, (_, i) => {
2936
+ return {
2937
+ active: i + 1 <= selectedValue
2938
+ };
2939
+ });
2940
+ }
2941
+ class Rating extends PureComponent {
2942
+ constructor(props) {
2943
+ super(props);
2944
+ this.setRating = rating => {
2945
+ const {
2946
+ maxRating,
2947
+ disabled
2948
+ } = this.props;
2949
+ if (disabled) {
2950
+ return;
2951
+ }
2952
+ this.setState({
2953
+ stars: generateStars(maxRating, rating)
2954
+ });
2955
+ };
2956
+ this.state = {
2957
+ stars: generateStars(props.maxRating, props.value)
2958
+ };
2959
+ }
2960
+ componentDidUpdate(prevProps) {
2961
+ const {
2962
+ maxRating,
2963
+ value
2964
+ } = this.props;
2965
+ if (prevProps.maxRating !== maxRating) {
2966
+ this.setState({
2967
+ stars: generateStars(maxRating, value)
2968
+ });
2969
+ }
2970
+ }
2971
+ render() {
2972
+ const {
2973
+ name,
2974
+ value,
2975
+ onChange,
2976
+ disabled,
2977
+ className
2978
+ } = this.props;
2979
+ const {
2980
+ stars
2981
+ } = this.state;
2982
+ const _className = cx(wrapStyle, className, disabled && disabledStyle);
2983
+ return /*#__PURE__*/createElement("div", {
2984
+ className: _className
2985
+ }, stars.map((star, starIndex) => {
2986
+ const rating = starIndex + 1;
2987
+ return /*#__PURE__*/createElement("span", {
2988
+ key: `${name}-${rating}`,
2989
+ onMouseEnter: () => this.setRating(rating),
2990
+ onMouseLeave: () => this.setRating(value),
2991
+ onClick: () => {
2992
+ if (disabled) {
2993
+ return;
2994
+ }
2995
+ this.setRating(rating);
2996
+ onChange(rating);
2997
+ }
2998
+ }, /*#__PURE__*/createElement("i", {
2999
+ className: cx("pi pi-grade", unSelectedStar, star.active && selectedStar)
3000
+ }));
3001
+ }));
3002
+ }
3003
+ }
3004
+
2890
3005
  const inputReadOnlyStyle$1 = /*#__PURE__*/css({
2891
3006
  color: colors.gray.dark
2892
3007
  }, ";label:inputReadOnlyStyle;" + ( "" ));
@@ -3504,7 +3619,7 @@ const labelTextStyle = /*#__PURE__*/css({ ...typography.s.bold,
3504
3619
  color: colors.gray.dark,
3505
3620
  marginRight: "10px"
3506
3621
  }, ";label:labelTextStyle;" + ( "" ));
3507
- const disabledStyle = /*#__PURE__*/css( {
3622
+ const disabledStyle$1 = /*#__PURE__*/css( {
3508
3623
  name: "pl7a4e-disabledStyle",
3509
3624
  styles: "cursor:not-allowed;;label:disabledStyle;"
3510
3625
  } );
@@ -3562,14 +3677,14 @@ class Switch extends PureComponent {
3562
3677
  } = this.state;
3563
3678
  return /*#__PURE__*/createElement("label", {
3564
3679
  className: cx(className, fixedLabelStyle, {
3565
- [disabledStyle]: !!disabled
3680
+ [disabledStyle$1]: !!disabled
3566
3681
  })
3567
3682
  }, /*#__PURE__*/createElement("span", {
3568
3683
  className: labelTextStyle
3569
3684
  }, label), /*#__PURE__*/createElement("div", {
3570
3685
  className: cx(labelStyle$1, {
3571
3686
  [selectedLabel]: value,
3572
- [disabledStyle]: !!disabled
3687
+ [disabledStyle$1]: !!disabled
3573
3688
  })
3574
3689
  }, /*#__PURE__*/createElement("input", {
3575
3690
  type: "checkbox",
@@ -4030,5 +4145,5 @@ var index = /*#__PURE__*/Object.freeze({
4030
4145
  isDesktop: isDesktop
4031
4146
  });
4032
4147
 
4033
- export { BrowserBasedDateInput, Button, Calendar, Checkbox, CheckboxGroup, DateInput, DropDown, DropDownButton, Input, Loader, Logo, Message, Modal, NativeDateInput, Option, OptionGroup, OptionGroupCheckBox, OptionGroupRadio, OutsideClick, PhoneNumberInput, PopUp, PebblePopper as Popper, PresetCalendar, Radio, RadioGroup, Search, SecondaryInput, Select, SideBar, Slider, Stepper, Switch, TabSection, Tabs, Tag, Text, TimePicker, Toast, Tooltip, TypeAhead, UserAgentInfoContext, UserAgentInfoProvider, constants, mixins, styles, typography, index as utils };
4148
+ export { BrowserBasedDateInput, Button, Calendar, Checkbox, CheckboxGroup, DateInput, DropDown, DropDownButton, Input, Loader, Logo, Message, Modal, NativeDateInput, Option, OptionGroup, OptionGroupCheckBox, OptionGroupRadio, OutsideClick, PhoneNumberInput, PopUp, PebblePopper as Popper, PresetCalendar, Radio, RadioGroup, Rating, Search, SecondaryInput, Select, SideBar, Slider, Stepper, Switch, TabSection, Tabs, Tag, Text, TimePicker, Toast, Tooltip, TypeAhead, UserAgentInfoContext, UserAgentInfoProvider, constants, mixins, styles, typography, index as utils };
4034
4149
  //# sourceMappingURL=pebble-web.es.js.map