Skip to content

Commit

Permalink
RC #291 - Adding FacetTimeline component; Adding "actions" prop to Fa…
Browse files Browse the repository at this point in the history
…cetSlider component; Moving ModalContext to shared package (breaking)
  • Loading branch information
dleadbetter committed Aug 9, 2024
1 parent 92980ea commit b3b55de
Show file tree
Hide file tree
Showing 34 changed files with 827 additions and 141 deletions.
3 changes: 2 additions & 1 deletion packages/core-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"dependencies": {
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-slider": "^1.2.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@samvera/clover-iiif": "^2.3.2",
Expand Down
11 changes: 9 additions & 2 deletions packages/core-data/src/components/EventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import LoadAnimation from './LoadAnimation';
import { useEventsService, useLoader } from '../hooks/CoreData';

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

/**
* Identifier for the event to fetch.
*/
Expand All @@ -25,7 +30,7 @@ const EventDetails = (props: Props) => {
*/
const onLoad = useCallback(() => EventsService.fetchOne(props.id), [props.id]);

const { data: { event } = {}, loading } = useLoader(onLoad);
const { data: { event } = {}, loading } = useLoader(onLoad, {}, [props.id]);

if (loading) {
return (
Expand All @@ -38,7 +43,9 @@ const EventDetails = (props: Props) => {
}

return (
<div>
<div
className={props.className}
>
<h1
className='pr-6 py-1 font-bold text-2xl'
>
Expand Down
99 changes: 99 additions & 0 deletions packages/core-data/src/components/EventsList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// @flow

import clsx from 'clsx';
import React from 'react';
import _ from 'underscore';
import type { Event as EventType } from '../types/Event';
import EventUtils from '../utils/Event';

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

/**
* If `true`, the event description will be displayed on the card.
*/
description?: boolean,

/**
* The list of events records to display.
*/
events: Array<EventType>,

/**
* Callback that returns `true` if the passed event is selected.
*/
isSelected?: (event: EventType) => boolean,

/**
* Callback fired when the event row is clicked.
*/
onClick?: (event: EventType) => void
};

const EventsList = (props: Props) => (
<ul
className={props.className}
>
{ _.map(props.events, (event) => (
<li>
<div
className='min-h-[5.5em] border-b flex flex-col justify-start'
>
<button
className={clsx(
'py-3',
'px-4',
'flex-grow',
'text-left',
'inline-flex',
'flex-col',
'rounded-none',
{ 'hover:bg-event-selected': props.isSelected(event) },
{ 'text-white': props.isSelected(event) },
{ 'bg-event-selected': props.isSelected(event) }
)}
onClick={() => props.onClick(event)}
type='button'
>
<div
className='flex justify-between w-full items-center'
>
<div
className='flex-grow'
>
<div>
{ EventUtils.getDateView(event) }
</div>
<h2
className='text-xl font-bold'
>
{ event.name }
</h2>
</div>
</div>
{ props.description && (
<p
className={clsx(
'py-2',
{ 'text-muted': !props.isSelected(event) }
)}
>
{ event.description }
</p>
)}
</button>
</div>
</li>
))}
</ul>
);

EventsList.defaultProps = {
isSelected: () => false,
onClick: () => {}
};

export default EventsList;
81 changes: 69 additions & 12 deletions packages/core-data/src/components/FacetSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ZoomOut
} from 'lucide-react';
import React, { useCallback, useEffect, useState } from 'react';
import _ from 'underscore';

type MarkerProps = {
className?: string,
Expand Down Expand Up @@ -75,7 +76,7 @@ const SliderMarker = (props: MarkerProps) => {
sideOffset={5}
>
<div
className='bg-white p-2 text-black rounded-md shadow-md'
className='bg-white p-2 text-black rounded-md shadow-md shadow-gray-1000'
>
{ props.value }
</div>
Expand All @@ -88,17 +89,47 @@ const SliderMarker = (props: MarkerProps) => {
);
};

type Action = {
/**
* Class name to apply to the button element.
*/
className?: string,

/**
* (Optional) icon to render inside the button element.
*/
icon?: JSX.Element,

/**
* Button label.
*/
label: string,

/**
* Callback fired when the button is clicked.
*/
onClick: () => void
};

type ClassNames = {
button: string,
range: string,
root: string,
thumb: string,
track: string,
zoom: string
};

type Props = {
/**
* Custom actions to render as buttons.
*/
actions?: Array<Action>,

/**
* Custom Tailwind CSS class names.
*/
classNames: {
button: string,
range: string,
root: string,
thumb: string,
track: string
},
classNames: ClassNames,

/**
* The maximum facet value.
Expand All @@ -113,7 +144,7 @@ type Props = {
/**
* Callback fired when the range is changed.
*/
onChange?: ([number, number]) => void,
onChange?: ([[number, number], [number, number]]) => void,

/**
* Number of steps to increment the slider.
Expand Down Expand Up @@ -224,9 +255,9 @@ const FacetSlider = (props: Props) => {
*/
useEffect(() => {
if (props.onChange) {
props.onChange(range);
props.onChange(range, [min, max]);
}
}, [range]);
}, [max, min, range]);

return (
<>
Expand Down Expand Up @@ -292,7 +323,10 @@ const FacetSlider = (props: Props) => {
</div>
{ props.zoom && (
<div
className='flex justify-center items-center w-full py-3 text-gray-600'
className={clsx(
'flex justify-center items-center w-full py-3 text-gray-600',
props.classNames.zoom
)}
>
<button
aria-label='Zoom In'
Expand All @@ -318,6 +352,24 @@ const FacetSlider = (props: Props) => {
>
<RotateCcw />
</button>
{ !_.isEmpty(props.actions) && (
<>
{ _.map(props.actions, (action, index) => (
<button
aria-label={action.label}
className={clsx(
'p-3',
action.className
)}
key={index}
onClick={action.onClick}
type='button'
>
{ action.icon }
</button>
))}
</>
)}
</div>
)}
</>
Expand All @@ -330,3 +382,8 @@ FacetSlider.defaultProps = {
};

export default FacetSlider;

export type {
Action,
ClassNames
};
Loading

0 comments on commit b3b55de

Please sign in to comment.