@mackin.com/styleguide 9.3.2 → 9.4.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.
Files changed (3) hide show
  1. package/index.d.ts +12 -4
  2. package/index.js +21 -3
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -51,7 +51,7 @@ interface AutocompleteProps extends BaseInputProps$1 {
51
51
  allowScroll?: boolean;
52
52
  /** Delay before the input is re-focused after picking a value. Adjust if there are issues with the displayed input value after pick. Defaults to 100ms. */
53
53
  onPickFocusWaitMs?: number;
54
- onPick: (value: string | undefined) => void;
54
+ onPick: (value: string | undefined, index?: number) => void;
55
55
  }
56
56
  declare const Autocomplete: (p: AutocompleteProps) => JSX.Element;
57
57
 
@@ -566,12 +566,22 @@ interface Props<T> extends PagerStyleProps {
566
566
  }
567
567
  declare const BoundStaticPager: <T>(p: Props<T>) => JSX.Element;
568
568
 
569
+ interface PagedResultDto<T> {
570
+ total: number;
571
+ /** The zero-based page index. */
572
+ page: number;
573
+ limit: number;
574
+ items: T[];
575
+ }
576
+
569
577
  /** A page of data with helpers props. */
570
578
  declare class PagedResult<T> {
571
579
  constructor(items?: T[], total?: number, page?: number, limit?: number);
580
+ /** @deprecated Use fromPagedResultDto going forward. */
572
581
  static fromDto<T>(dto: {
573
582
  [key: string]: any;
574
583
  }): PagedResult<T>;
584
+ static fromPagedResultDto<TDto, TDomain>(dto: PagedResultDto<TDto>, convert?: (dto: TDto) => TDomain): PagedResult<TDomain>;
575
585
  total: number;
576
586
  /** The zero-based page index. */
577
587
  page: number;
@@ -597,9 +607,7 @@ declare class PagedResult<T> {
597
607
  getPreviousItem(fromItem: T): T | undefined;
598
608
  getNextItem(fromItem: T): T | undefined;
599
609
  getPagingRange(radius: number): number[];
600
- toJSON(): {
601
- [key: string]: any;
602
- };
610
+ toJSON(): PagedResultDto<T>;
603
611
  clone(newItems?: T[]): PagedResult<T>;
604
612
  }
605
613
 
package/index.js CHANGED
@@ -966,7 +966,7 @@ const buttonMarkerClass = 'ListItem__button';
966
966
  const defaultOnPickFocusMs = 100;
967
967
  const Autocomplete = (p) => {
968
968
  var _a;
969
- const inputProps = __rest(p, ["value", "className", "inputWrapperClassName", "inputClassName", "maxShownValues", "allowScroll", "options", "onPick", "onPickFocusWaitMs"]);
969
+ const inputProps = __rest(p, ["value", "className", "inputWrapperClassName", "inputClassName", "listClassName", "listItemClassName", "listItemButtonClassName", "maxShownValues", "allowScroll", "options", "onPick", "onPickFocusWaitMs"]);
970
970
  const theme = useThemeSafely();
971
971
  const element = React__namespace.useRef(null);
972
972
  const input = React__namespace.useRef(null);
@@ -1020,7 +1020,11 @@ const Autocomplete = (p) => {
1020
1020
  setTimeout(() => {
1021
1021
  // blur is now complete
1022
1022
  var _a;
1023
- p.onPick(v);
1023
+ let index = v ? p.options.findIndex(o => o === v) : undefined;
1024
+ if (index !== undefined && index < 0) {
1025
+ index = undefined;
1026
+ }
1027
+ p.onPick(v, index);
1024
1028
  // wait for the re-render. the value will not update if the control has focus
1025
1029
  setTimeout(() => {
1026
1030
  var _a;
@@ -3223,9 +3227,14 @@ class PagedResult {
3223
3227
  this.limit = limit;
3224
3228
  this.total = total;
3225
3229
  }
3230
+ /** @deprecated Use fromPagedResultDto going forward. */
3226
3231
  static fromDto(dto) {
3227
3232
  return new PagedResult(dto.items, dto.total, dto.page, dto.limit);
3228
3233
  }
3234
+ static fromPagedResultDto(dto, convert) {
3235
+ const items = convert ? dto.items.map(convert) : dto.items;
3236
+ return new PagedResult(items, dto.total, dto.page, dto.limit);
3237
+ }
3229
3238
  /** Helper for items.length */
3230
3239
  get length() {
3231
3240
  return this.items ? this.items.length : 0;
@@ -3697,10 +3706,19 @@ const GlobalStyles = (p) => {
3697
3706
  const Slider = (p) => {
3698
3707
  var _a;
3699
3708
  const theme = useThemeSafely();
3700
- const currentValue = React.useRef(p.value);
3701
3709
  const sliderContainer = React.useRef(null);
3702
3710
  const sliderHandleSize = (_a = p.sliderHandleSize) !== null && _a !== void 0 ? _a : theme.controls.height;
3703
3711
  const height = p.showValue ? `calc(${sliderHandleSize} + 1.5rem)` : sliderHandleSize;
3712
+ // we're keeping this value in a ref vs. state so the constant updates don't cause re-render.
3713
+ // we will have to respond to outside value changes after the fact however...
3714
+ const currentValue = React.useRef(p.value);
3715
+ const [, forceUpdate] = React.useState(Date.now());
3716
+ React.useEffect(() => {
3717
+ if (p.value !== currentValue.current) {
3718
+ currentValue.current = p.value;
3719
+ forceUpdate(Date.now());
3720
+ }
3721
+ }, [p.value]);
3704
3722
  return (React__default['default'].createElement("div", { ref: sliderContainer, className: css.cx(css.css({
3705
3723
  label: 'Slider',
3706
3724
  width: '100%',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "9.3.2",
3
+ "version": "9.4.0",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",