@databiosphere/findable-ui 2.0.1 → 2.1.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.
@@ -8,7 +8,7 @@ const styled_1 = __importDefault(require("@emotion/styled"));
8
8
  const material_1 = require("@mui/material");
9
9
  const breakpoints_1 = require("../../../../styles/common/mixins/breakpoints");
10
10
  exports.FilterLabel = (0, styled_1.default)(material_1.Button) `
11
- color: ${({ theme }) => theme.palette.ink.main};
11
+ font-weight: inherit;
12
12
  gap: 0;
13
13
  justify-content: space-between;
14
14
  padding: 10px 16px;
@@ -20,7 +20,6 @@ exports.FilterLabel = (0, styled_1.default)(material_1.Button) `
20
20
  }
21
21
 
22
22
  &.Mui-disabled {
23
- color: ${({ theme }) => theme.palette.ink.main};
24
23
  opacity: 0.3;
25
24
  }
26
25
 
@@ -65,11 +65,13 @@ const Filters = ({ categoryFilters, closeAncestor, disabled = false, onFilter, t
65
65
  const { height: windowHeight } = (0, useWindowResize_1.useWindowResize)();
66
66
  const filterListRef = (0, react_1.useRef)(null);
67
67
  const [height, setHeight] = (0, react_1.useState)(0);
68
+ const isLabeled = (0, react_1.useMemo)(() => isCategoryViewsLabeled(categoryFilters), [categoryFilters]);
68
69
  (0, react_1.useEffect)(() => {
69
70
  setHeight(calculateListHeight(windowHeight, filterListRef.current));
70
71
  }, [windowHeight]);
71
- return (react_1.default.createElement(filters_styles_1.Filters, { disabled: disabled, height: height, ref: filterListRef }, categoryFilters.map(({ categoryViews, label }, i) => (react_1.default.createElement(react_1.Fragment, { key: i },
72
+ return (react_1.default.createElement(filters_styles_1.Filters, { disabled: disabled, height: height, isBaseStyle: !isLabeled, ref: filterListRef }, categoryFilters.map(({ categoryViews, label }, i) => (react_1.default.createElement(react_1.Fragment, { key: i },
72
73
  i !== 0 && react_1.default.createElement(material_1.Divider, null),
74
+ label && react_1.default.createElement(filters_styles_1.CategoryViewsLabel, null, label),
73
75
  categoryViews.map((categoryView) => (react_1.default.createElement(filter_1.Filter, { key: categoryView.key, categorySection: label, categoryView: categoryView, closeAncestor: closeAncestor, isFilterDrawer: isFilterDrawer, onFilter: onFilter, trackFilterOpened: trackFilterOpened, tags: renderFilterTags(categoryView, onFilter) }))))))));
74
76
  };
75
77
  exports.Filters = Filters;
@@ -83,3 +85,11 @@ function calculateListHeight(windowHeight, filterListEl) {
83
85
  var _a, _b;
84
86
  return windowHeight - ((_b = (_a = filterListEl === null || filterListEl === void 0 ? void 0 : filterListEl.getBoundingClientRect()) === null || _a === void 0 ? void 0 : _a.top) !== null && _b !== void 0 ? _b : 0);
85
87
  }
88
+ /**
89
+ * Returns true if any category views are labelled.
90
+ * @param categoryFilters - Category filters.
91
+ * @returns true if any category views are labelled.
92
+ */
93
+ function isCategoryViewsLabeled(categoryFilters) {
94
+ return categoryFilters.some(({ label }) => label);
95
+ }
@@ -2,9 +2,14 @@
2
2
  interface Props {
3
3
  disabled: boolean;
4
4
  height: number;
5
+ isBaseStyle: boolean;
5
6
  }
6
7
  export declare const Filters: import("@emotion/styled").StyledComponent<{
7
8
  theme?: import("@emotion/react").Theme | undefined;
8
9
  as?: import("react").ElementType<any> | undefined;
9
10
  } & Props, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
11
+ export declare const CategoryViewsLabel: import("@emotion/styled").StyledComponent<{
12
+ theme?: import("@emotion/react").Theme | undefined;
13
+ as?: import("react").ElementType<any> | undefined;
14
+ }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
10
15
  export {};
@@ -3,13 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Filters = void 0;
6
+ exports.CategoryViewsLabel = exports.Filters = void 0;
7
7
  const react_1 = require("@emotion/react");
8
8
  const styled_1 = __importDefault(require("@emotion/styled"));
9
9
  const breakpoints_1 = require("../../../../styles/common/mixins/breakpoints");
10
+ const colors_1 = require("../../../../styles/common/mixins/colors");
11
+ const fonts_1 = require("../../../../styles/common/mixins/fonts");
10
12
  exports.Filters = (0, styled_1.default)("div", {
11
13
  shouldForwardProp: (prop) => prop !== "height",
12
14
  }) `
15
+ ${(props) => (props.isBaseStyle ? (0, fonts_1.textBody500)(props) : (0, fonts_1.textBody400)(props))};
16
+ color: ${(props) => (props.isBaseStyle ? (0, colors_1.inkMain)(props) : (0, colors_1.inkLight)(props))};
13
17
  height: ${({ height }) => height}px;
14
18
  margin: 8px 0;
15
19
  overflow: auto;
@@ -31,3 +35,12 @@ exports.Filters = (0, styled_1.default)("div", {
31
35
  padding: 0 12px 0 16px;
32
36
  }
33
37
  `;
38
+ exports.CategoryViewsLabel = (0, styled_1.default)("div") `
39
+ ${fonts_1.textBody500};
40
+ color: ${colors_1.inkMain};
41
+ padding: 8px 16px;
42
+
43
+ ${breakpoints_1.mediaDesktopSmallUp} {
44
+ padding: 8px 0;
45
+ }
46
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databiosphere/findable-ui",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -3,7 +3,7 @@ import { Button } from "@mui/material";
3
3
  import { mediaDesktopSmallUp } from "../../../../styles/common/mixins/breakpoints";
4
4
 
5
5
  export const FilterLabel = styled(Button)`
6
- color: ${({ theme }) => theme.palette.ink.main};
6
+ font-weight: inherit;
7
7
  gap: 0;
8
8
  justify-content: space-between;
9
9
  padding: 10px 16px;
@@ -15,7 +15,6 @@ export const FilterLabel = styled(Button)`
15
15
  }
16
16
 
17
17
  &.Mui-disabled {
18
- color: ${({ theme }) => theme.palette.ink.main};
19
18
  opacity: 0.3;
20
19
  }
21
20
 
@@ -1,15 +1,23 @@
1
1
  import { css } from "@emotion/react";
2
2
  import styled from "@emotion/styled";
3
3
  import { mediaDesktopSmallUp } from "../../../../styles/common/mixins/breakpoints";
4
+ import { inkLight, inkMain } from "../../../../styles/common/mixins/colors";
5
+ import {
6
+ textBody400,
7
+ textBody500,
8
+ } from "../../../../styles/common/mixins/fonts";
4
9
 
5
10
  interface Props {
6
11
  disabled: boolean;
7
12
  height: number;
13
+ isBaseStyle: boolean;
8
14
  }
9
15
 
10
16
  export const Filters = styled("div", {
11
17
  shouldForwardProp: (prop) => prop !== "height",
12
18
  })<Props>`
19
+ ${(props) => (props.isBaseStyle ? textBody500(props) : textBody400(props))};
20
+ color: ${(props) => (props.isBaseStyle ? inkMain(props) : inkLight(props))};
13
21
  height: ${({ height }) => height}px;
14
22
  margin: 8px 0;
15
23
  overflow: auto;
@@ -32,3 +40,13 @@ export const Filters = styled("div", {
32
40
  padding: 0 12px 0 16px;
33
41
  }
34
42
  `;
43
+
44
+ export const CategoryViewsLabel = styled("div")`
45
+ ${textBody500};
46
+ color: ${inkMain};
47
+ padding: 8px 16px;
48
+
49
+ ${mediaDesktopSmallUp} {
50
+ padding: 8px 0;
51
+ }
52
+ `;
@@ -1,6 +1,6 @@
1
1
  import { Divider } from "@mui/material";
2
2
  import { TrackFilterOpenedFunction } from "config/entities";
3
- import React, { Fragment, useEffect, useRef, useState } from "react";
3
+ import React, { Fragment, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { CategoryTag, SelectCategoryView } from "../../../../common/entities";
5
5
  import {
6
6
  BREAKPOINT_FN_NAME,
@@ -11,7 +11,7 @@ import { useWindowResize } from "../../../../hooks/useWindowResize";
11
11
  import { DESKTOP_SM } from "../../../../theme/common/breakpoints";
12
12
  import { Filter } from "../Filter/filter";
13
13
  import { FilterTags } from "../FilterTags/filterTags";
14
- import { Filters as FilterList } from "./filters.styles";
14
+ import { CategoryViewsLabel, Filters as FilterList } from "./filters.styles";
15
15
 
16
16
  export interface CategoryFilter {
17
17
  categoryViews: SelectCategoryView[];
@@ -76,16 +76,26 @@ export const Filters = ({
76
76
  const { height: windowHeight } = useWindowResize();
77
77
  const filterListRef = useRef<HTMLDivElement>(null);
78
78
  const [height, setHeight] = useState<number>(0);
79
+ const isLabeled = useMemo(
80
+ () => isCategoryViewsLabeled(categoryFilters),
81
+ [categoryFilters]
82
+ );
79
83
 
80
84
  useEffect(() => {
81
85
  setHeight(calculateListHeight(windowHeight, filterListRef.current));
82
86
  }, [windowHeight]);
83
87
 
84
88
  return (
85
- <FilterList disabled={disabled} height={height} ref={filterListRef}>
89
+ <FilterList
90
+ disabled={disabled}
91
+ height={height}
92
+ isBaseStyle={!isLabeled}
93
+ ref={filterListRef}
94
+ >
86
95
  {categoryFilters.map(({ categoryViews, label }, i) => (
87
96
  <Fragment key={i}>
88
97
  {i !== 0 && <Divider />}
98
+ {label && <CategoryViewsLabel>{label}</CategoryViewsLabel>}
89
99
  {categoryViews.map((categoryView) => (
90
100
  <Filter
91
101
  key={categoryView.key}
@@ -116,3 +126,12 @@ function calculateListHeight(
116
126
  ): number {
117
127
  return windowHeight - (filterListEl?.getBoundingClientRect()?.top ?? 0);
118
128
  }
129
+
130
+ /**
131
+ * Returns true if any category views are labelled.
132
+ * @param categoryFilters - Category filters.
133
+ * @returns true if any category views are labelled.
134
+ */
135
+ function isCategoryViewsLabeled(categoryFilters: CategoryFilter[]): boolean {
136
+ return categoryFilters.some(({ label }) => label);
137
+ }