Skip to content

Commit

Permalink
Merge pull request #307 from performant-software/feature/basira290_fa…
Browse files Browse the repository at this point in the history
…cet_tooltip

BASIRA #290 - Facet tooltip
  • Loading branch information
dleadbetter authored Dec 23, 2024
2 parents ca85a9c + 1b258ba commit a1cc8a6
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 29 deletions.
6 changes: 3 additions & 3 deletions packages/controlled-vocabulary/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/controlled-vocabulary",
"version": "2.2.19",
"version": "2.2.20",
"description": "A package of components to allow user to configure dropdown elements. Use with the \"controlled_vocabulary\" gem.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand All @@ -23,8 +23,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/semantic-components": "^2.2.19",
"@performant-software/shared-components": "^2.2.19",
"@performant-software/semantic-components": "^2.2.20",
"@performant-software/shared-components": "^2.2.20",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/core-data",
"version": "2.2.19",
"version": "2.2.20",
"description": "A package of components used with the Core Data platform.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -40,8 +40,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/geospatial": "^2.2.19",
"@performant-software/shared-components": "^2.2.19",
"@performant-software/geospatial": "^2.2.20",
"@performant-software/shared-components": "^2.2.20",
"@peripleo/maplibre": "^0.5.2",
"@peripleo/peripleo": "^0.5.2",
"react": ">= 16.13.1 < 19.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/geospatial/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/geospatial",
"version": "2.2.19",
"version": "2.2.20",
"description": "A package of components for all things map-related.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/semantic-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/semantic-components",
"version": "2.2.19",
"version": "2.2.20",
"description": "A package of shared components based on the Semantic UI Framework.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -35,7 +35,7 @@
"zotero-translation-client": "^5.0.1"
},
"peerDependencies": {
"@performant-software/shared-components": "^2.2.19",
"@performant-software/shared-components": "^2.2.20",
"@samvera/clover-iiif": "^2.3.2",
"react": ">= 16.13.1 < 19.0.0",
"react-dnd": "^11.1.3",
Expand Down
12 changes: 12 additions & 0 deletions packages/semantic-ui/src/components/Facet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import React, {
useEffect,
useImperativeHandle,
useMemo,
useState,
Expand Down Expand Up @@ -42,6 +43,11 @@ type Props = {
current: ?HTMLElement
},

/**
* Callback fired when the facet active state is toggled.
*/
onActive?: () => void,

/**
* Facet title to display at the top.
*/
Expand Down Expand Up @@ -86,6 +92,12 @@ const Facet = (props: Props) => {
expand: () => setActive(true)
}));

useEffect(() => {
if (active && props.onActive) {
props.onActive();
}
}, [active]);

return (
<>
<Accordion
Expand Down
4 changes: 4 additions & 0 deletions packages/semantic-ui/src/components/FacetList.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
display: block;
margin-top: 1em;
}

.facet-list.ui.list > .item > .ui.checkbox {
width: 100%;
}
45 changes: 32 additions & 13 deletions packages/semantic-ui/src/components/FacetList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import { type RefinementListProps } from '../types/InstantSearch';
import './FacetList.css';

type Props = FacetProps & RefinementListProps & {
/**
* (Optional) class name to append to the root element.
*/
className?: string,

/**
* The default value for the `operator` prop. If not provided, this will default to `or`.
*/
Expand All @@ -34,6 +39,11 @@ type Props = FacetProps & RefinementListProps & {
*/
defaultValue?: string,

/**
* Renders a custom label element for the passed item.
*/
renderLabel?: (item: any) => JSX.Element,

/**
* If "true", the component will render a search box for searching individual facet values.
*/
Expand All @@ -45,6 +55,7 @@ type Props = FacetProps & RefinementListProps & {
toggleable?: boolean
};

const CLASS_SEPARATOR = ' ';
const OPERATOR_OR = 'or';
const OPERATOR_AND = 'and';

Expand All @@ -68,6 +79,11 @@ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLE
const searchRef = useRef();
const [query, setQuery] = useState('');

/**
* Memo-izes the class name.
*/
const className = useMemo(() => _.compact(['facet-list', props.className]).join(CLASS_SEPARATOR), [props.className]);

/**
* Clears the current search state.
*
Expand Down Expand Up @@ -128,10 +144,11 @@ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLE

return (
<Facet
className='facet-list'
className={className}
defaultActive={props.defaultActive}
divided={props.divided}
innerRef={ref}
onActive={props.onActive}
title={props.title}
visible={visible}
>
Expand All @@ -156,23 +173,25 @@ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLE
<List
className='facet-list'
>
{ _.map(items, (item, index) => (
{ _.map(items, (item) => (
<List.Item
key={index}
key={item.value}
>
<Checkbox
checked={item.isRefined}
label={{
children: (
<>
<span>{ item.label }</span>
<Label
circular
content={item.count}
size='small'
/>
</>
)
children: props.renderLabel
? props.renderLabel(item)
: (
<>
<span>{ item.label }</span>
<Label
circular
content={item.count}
size='small'
/>
</>
)
}}
onClick={() => refine(item.value)}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/shared-components",
"version": "2.2.19",
"version": "2.2.20",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
75 changes: 74 additions & 1 deletion packages/storybook/src/semantic-ui/FacetList.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { action } from '@storybook/addon-actions';
import React, { useCallback, useRef } from 'react';
import { Button } from 'semantic-ui-react';
import { Button, Checkbox, List } from 'semantic-ui-react';
import FacetList from '../../../semantic-ui/src/components/FacetList';

export default {
Expand Down Expand Up @@ -227,3 +227,76 @@ export const ExpandCollapse = () => {
</>
);
};

export const CustomRender = () => (
<FacetList
renderLabel={(item) => (
<div
style={{
display: 'flex',
justifyContent: 'space-between',
width: '100%'
}}
>
<span>{ item.label }</span>
<span>{ item.count }</span>
</div>
)}
title='Make'
useRefinementList={() => ({
items: [{
label: 'Chevrolet',
count: 783,
value: 'chevrolet'
}, {
label: 'Ford',
count: 399,
value: 'ford'
}, {
label: 'Toyota',
count: 236,
value: 'toyota'
}, {
label: 'Acura',
count: 122,
value: 'acura'
}],
refine: action('refine'),
canToggleShowMore: false,
isShowingMore: false,
searchForItems: action('search'),
toggleShowMore: action('show more')
})}
/>
);

export const onActive = () => (
<FacetList
onActive={action('active')}
title='Make'
useRefinementList={() => ({
items: [{
label: 'Chevrolet',
count: 783,
value: 'chevrolet'
}, {
label: 'Ford',
count: 399,
value: 'ford'
}, {
label: 'Toyota',
count: 236,
value: 'toyota'
}, {
label: 'Acura',
count: 122,
value: 'acura'
}],
refine: action('refine'),
canToggleShowMore: false,
isShowingMore: false,
searchForItems: action('search'),
toggleShowMore: action('show more')
})}
/>
);
6 changes: 3 additions & 3 deletions packages/user-defined-fields/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/user-defined-fields",
"version": "2.2.19",
"version": "2.2.20",
"description": "A package of components used for allowing end users to define fields on models. Use with the \"user_defined_fields\" gem.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand All @@ -23,8 +23,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/semantic-components": "^2.2.19",
"@performant-software/shared-components": "^2.2.19",
"@performant-software/semantic-components": "^2.2.20",
"@performant-software/shared-components": "^2.2.20",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/visualize",
"version": "2.2.19",
"version": "2.2.20",
"description": "A package of components used for data visualization",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion react-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"packages/user-defined-fields",
"packages/visualize"
],
"version": "2.2.19"
"version": "2.2.20"
}

0 comments on commit a1cc8a6

Please sign in to comment.