-
Notifications
You must be signed in to change notification settings - Fork 4
#270: Table of Contents Dropdown Implementation + Dropdown styling cleanup #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c0b3dc4
initialize the table of contents component
SaqAsh 8d9f78d
handle logic for the actual scrolling into view for scheams
SaqAsh ee3a2c9
clean up the table of contents, add the relevant functions
SaqAsh 9f2bd1d
cleanup css styling such that it is uniform and has no unessesary att…
SaqAsh 5414669
fix subpar styling for dropdown
SaqAsh c10619c
code cleanup
SaqAsh ffa06e0
add an advanced.json to better facilitate visualation of table of con…
SaqAsh ce91494
fix naming issue with list
SaqAsh edc0902
moving dropdown into the interaction panel
SaqAsh 41baefa
use theme context instead of individually importing the icon
SaqAsh 0c97a59
finalizing the styling according to the figma
SaqAsh 50a8e5c
Merge branch 'main' into feature/Table-of-contents
SaqAsh fe1dd0e
move advanced.json and fix import
SaqAsh 9f29bf9
we want user inputted styles to be in highest priority
SaqAsh 35556bb
export props
SaqAsh 902eccc
change from console.log to alert
SaqAsh 7db7058
implement pr review changes
SaqAsh 34445e9
accidentally removed export
SaqAsh e9a068e
fix naming inside of stories to make it consistent with props
SaqAsh 2e8400a
Merge branch 'main' into feature/Table-of-contents
SaqAsh 8ae8b69
remove set timeout used for debugging purposes
SaqAsh 92fce9e
remove classname
SaqAsh 288782b
address final pr review
SaqAsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2025 The Ontario Institute for Cancer Research. All rights reserved | ||
| * | ||
| * This program and the accompanying materials are made available under the terms of | ||
| * the GNU Affero General Public License v3.0. You should have received a copy of the | ||
| * GNU Affero General Public License along with this program. | ||
| * If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
| * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
| * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| /** @jsxImportSource @emotion/react */ | ||
|
|
||
| import { css } from '@emotion/react'; | ||
|
|
||
| import IconProps from './IconProps'; | ||
|
|
||
| const List = ({ fill, width, height, style }: IconProps) => { | ||
| return ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width={width || 24} | ||
| height={height || 24} | ||
| viewBox="0 0 24 24" | ||
| fill={fill || 'none'} | ||
| stroke="currentColor" | ||
| strokeWidth="2" | ||
| strokeLinecap="round" | ||
| strokeLinejoin="round" | ||
| css={css` | ||
| ${style} | ||
| `} | ||
| > | ||
| <path d="M3 12h.01" /> | ||
| <path d="M3 18h.01" /> | ||
| <path d="M3 6h.01" /> | ||
| <path d="M8 12h13" /> | ||
| <path d="M8 18h13" /> | ||
| <path d="M8 6h13" /> | ||
| </svg> | ||
| ); | ||
| }; | ||
|
|
||
| export default List; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import ChevronDown from '../icons/ChevronDown'; | ||
| import List from '../icons/List'; | ||
| export default { | ||
| ChevronDown, | ||
| List, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/ui/src/viewer-table/InteractionPanel/TableOfContentsDropdown.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2025 The Ontario Institute for Cancer Research. All rights reserved | ||
| * | ||
| * This program and the accompanying materials are made available under the terms of | ||
| * the GNU Affero General Public License v3.0. You should have received a copy of the | ||
| * GNU Affero General Public License along with this program. | ||
| * If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
| * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
| * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| import type { Schema } from '@overture-stack/lectern-dictionary'; | ||
| import React from 'react'; | ||
| import Dropdown from '../../common/Dropdown/Dropdown'; | ||
| import { useThemeContext } from '../../theme/ThemeContext'; | ||
|
|
||
| export type TableOfContentsDropdownProps = { | ||
| schemas: Schema[]; | ||
| onSelect: (schemaIndex: number) => void; | ||
| }; | ||
|
|
||
| const TableOfContentsDropdown = ({ schemas, onSelect }: TableOfContentsDropdownProps) => { | ||
| const theme = useThemeContext(); | ||
| const { List } = theme.icons; | ||
| const handleAction = (index: number) => { | ||
| const anchorId = `#${index}`; | ||
| onSelect(index); | ||
| window.location.hash = anchorId; | ||
| }; | ||
|
|
||
| const menuItemsFromSchemas = schemas.map((schema, index) => ({ | ||
| label: schema.name, | ||
| action: () => { | ||
| handleAction(index); | ||
| }, | ||
| })); | ||
|
|
||
| return schemas.length > 0 ? | ||
| <Dropdown leftIcon={<List />} title="Table of Contents" menuItems={menuItemsFromSchemas} /> | ||
| : null; | ||
| }; | ||
|
|
||
| export default TableOfContentsDropdown; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "name": "Advanced", | ||
| "version": "1.0", | ||
| "schemas": [ | ||
| { | ||
| "name": "empty", | ||
| "description": "An empty schema with no fields.", | ||
| "fields": [] | ||
| }, | ||
| { | ||
| "name": "single_field", | ||
| "description": "A schema with a single field of type string.", | ||
| "fields": [{ "name": "single_string_field", "valueType": "string" }] | ||
| }, | ||
| { | ||
| "name": "multiple_fields", | ||
| "description": "A schema with multiple fields of different types.", | ||
| "fields": [ | ||
| { "name": "string_field", "valueType": "string" }, | ||
| { "name": "integer_field", "valueType": "integer" }, | ||
| { "name": "boolean_field", "valueType": "boolean" } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "primitives", | ||
| "description": "Includes one field of each primitive type without any restrictions. No Frills.", | ||
| "fields": [ | ||
| { "name": "boolean_field", "valueType": "boolean" }, | ||
| { "name": "integer_field", "valueType": "integer" }, | ||
| { "name": "number_field", "valueType": "number" }, | ||
| { "name": "string_field", "valueType": "string" } | ||
| ] | ||
| } | ||
| ] | ||
| } |
37 changes: 37 additions & 0 deletions
37
packages/ui/stories/viewer-table/interaction-panel/TableOfContentDropdown.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
|
|
||
| import { Schema } from '@overture-stack/lectern-dictionary'; | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import Dictionary from '../../fixtures/advanced.json'; | ||
| import TableOfContentsDropdown from '../../../src/viewer-table/InteractionPanel/TableOfContentsDropdown'; | ||
| import themeDecorator from '../../themeDecorator'; | ||
|
|
||
| const meta = { | ||
| component: TableOfContentsDropdown, | ||
| title: 'Viewer - Table/Interaction - Panel/Table of Contents Dropdown', | ||
| tags: ['autodocs'], | ||
| decorators: [themeDecorator()], | ||
| } satisfies Meta<typeof TableOfContentsDropdown>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| // Using the primitiveJson as a mock schema for demonstration purposes | ||
| const schemas: Schema[] = Dictionary.schemas as Schema[]; | ||
|
|
||
| // Mock functions for the story just to demonstrate interaction | ||
|
|
||
| const onSelect = (schemaIndex: number) => { | ||
| alert(`Accordion has been toggled for the following schema: ${schemas[schemaIndex].name}`); | ||
| }; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| schemas: schemas, | ||
| onSelect, | ||
| }, | ||
| }; | ||
|
|
||
| export const Empty: Story = { | ||
| args: { schemas: [], onSelect: () => {} }, | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re slack convo, yes this is a side effect, but it works ok here. TableOfContentsDropdown is specialized enough that having scrolling to a hash behaviour built in is fine.