feat(ui): create DescriptionList with DescriptionTerm and DescriptionDefinition#1486
feat(ui): create DescriptionList with DescriptionTerm and DescriptionDefinition#1486guoda-puidokaite wants to merge 17 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 051b951 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
ArtieReus
left a comment
There was a problem hiding this comment.
very cool!!! Added just some thoughts
| @@ -0,0 +1,14 @@ | |||
| /* | |||
| * SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | |||
There was a problem hiding this comment.
did you already have written the files in 2024????
There was a problem hiding this comment.
it applies to all files
| .dd { | ||
| display: grid; | ||
| align-items: center; | ||
| border-bottom: 1px solid var(--color-dd-dt-border); |
There was a problem hiding this comment.
If this is applied to the last row too, you may get an extra divider at the end.
| * Represents the definition or description in a description list, rendering as an HTML <dd> element. | ||
| * Pairs with DescriptionTerm to complete the term-description association, offering flexible content styling. | ||
| */ | ||
| export const DescriptionDefinition: React.FC<DescriptionDefinitionProps> = ({ children, className = "" }) => ( |
There was a problem hiding this comment.
Do we have a check <dd> is only valid inside a <dl>?
There was a problem hiding this comment.
Interesting (and somewhat fundamental) question.
We generally do not check for parent validity (we may do in some places, but I can't think of any from the top of my head).
We may check for the validity of children in some places where we do only allow a certain type of children, and then it is not necessarily about strict html validity, but also Juno-UI-Components architectural validity, but even there I doubt we are being 100% consistent tbh.
Short answer: In this case specifically we'd rather not do it., leave as is
The best we could do is display a React warning in the console OR throw an error and prevent the component from rendering. As a general rule we have decided against the latter and preserve some user responsibility. Also, users may choose to render a surrounding dl element themselves not using our component, and the result would be totally valid, we couldn't 100% detect that thus still emitting a warning.
|
|
||
| .dl { | ||
| display: grid; | ||
| grid-template-columns: 1fr 2fr; |
There was a problem hiding this comment.
grid-template-columns: 1fr 2fr; is simple and fine, but it hard-codes the proportion. If terms (.dt) can be long, they may wrap more than desired; if definitions are short, you “waste” space. Would be useful being overwritten by props?
There was a problem hiding this comment.
Yes, we shouldn't hardcode the proportion and choose a default that works in most cases. I think going with 1fr 3fr is a more sensible default. But we need to make this overwriteable by users and document what the default is, too.
Even if people figured out how they can overwrite the proportions it is currently not that easily accomplished due to how the CSS cascade works (the styles from the css file are applied after styles passed via class name which makes them hard to overwrite).
There was a problem hiding this comment.
Agreed, smth in the 25% to 30% range seems a good starting point.
We can add more complex behaviour later (https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/grid-template-columns).
| children: | ||
| | ReactElement<DescriptionTermProps | DescriptionDefinitionProps> | ||
| | Array<ReactElement<DescriptionTermProps | DescriptionDefinitionProps>> | ||
| | ReactElement<"div"> |
There was a problem hiding this comment.
why allowing a div element?
There was a problem hiding this comment.
Valid as per spec, so if we offer a component that basically just (re-)creates an html element, we should stick to the spec.
Makes total sense if you think about it, it allows for cleanly styling individual pairs of dt and dd elements (or groups of a single dt with multiple dd elements, which is also valid as per spec).
|
|
||
| /* Component Border Colors: */ | ||
| --border-color-theme-default: var(--color-default-border); | ||
| --border-color-theme-default: var(--color-dd-dt-border); |
There was a problem hiding this comment.
Danger: You are overwriting the default border color with the specific color for the dd/dt component!!! This looks like an accidental change. Did you mean to set --color-dd-dt-border to the value of --border-color-theme-default?
| * This component enforces structure by expecting child elements of DescriptionTerm or DescriptionDefinition, | ||
| * aligning them according to the specified terms alignment. | ||
| */ | ||
| export const DescriptionList: React.FC<DescriptionListProps> = ({ children, alignTerms = "left", className = "" }) => ( |
There was a problem hiding this comment.
Default alignment is right, not left (according to ticket)
| */ | ||
| export const DescriptionList: React.FC<DescriptionListProps> = ({ children, alignTerms = "left", className = "" }) => ( | ||
| <dl | ||
| className={`dl ${alignTerms === "right" ? "align-right" : "align-left"} ${className}`} |
There was a problem hiding this comment.
see above, wrong default alignment
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| .dd { |
There was a problem hiding this comment.
So far we have always been following the rule that styles should be specified in the component itself as tailwind styles. We use dedicated css files only in cases where doing it in tailwind is complicated or impossible. In this case there is nothing here that warrants a dedicated css file for the styles. Please remove and turn into tailwind styles as usual.
| */ | ||
|
|
||
| import React, { ReactNode } from "react" | ||
| import "./description-definition.css" |
There was a problem hiding this comment.
see above, please define style in a const using tailwind classes here
| display: contents; | ||
| } | ||
|
|
||
| .dl.align-left .dt { |
There was a problem hiding this comment.
These simple parent selectors can be done in tailwind via the group- selector. See here: https://tailwindcss.com/docs/hover-focus-and-other-states#styling-based-on-parent-state
Please move to component as tailwind styles. Also the next one.
| export const Default: Story = { | ||
| render: (args) => ( | ||
| <DescriptionList {...args}> | ||
| <DT>Warranty</DT> |
There was a problem hiding this comment.
Please add a few more dt/dd children so it's easier to understand the usecase (the typical case is multiple key/value pairs in a list)
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| .dt { |
There was a problem hiding this comment.
See above, please move styles to tailwind classes in component instead of separate css file.
| */ | ||
|
|
||
| import React, { ReactNode } from "react" | ||
| import "./description-term.css" |
There was a problem hiding this comment.
replace with inline tailwind styles (see above)
| @import "./components/ThemeToggle/themeToggle.css" layer(utilities); | ||
| @import "./components/DataGridRow/data-grid-row.css" layer(utilities); | ||
| @import "./components/SideNavigationItem/sidenavigationitem.css" layer(utilities); | ||
| @import "./components/DescriptionList/description-list.css" layer(utilities); |
There was a problem hiding this comment.
Remember to remove these imports after you've made the change to tailwind styles instead of separate css files.
There was a problem hiding this comment.
Changes (if any?) seem unrelated to DescriptionList? Please review and exclude the file (unless I'm missing something).
| * Represents the definition or description in a description list, rendering as an HTML <dd> element. | ||
| * Pairs with DescriptionTerm to complete the term-description association, offering flexible content styling. | ||
| */ | ||
| export const DescriptionDefinition: React.FC<DescriptionDefinitionProps> = ({ children, className = "" }) => ( |
There was a problem hiding this comment.
Interesting (and somewhat fundamental) question.
We generally do not check for parent validity (we may do in some places, but I can't think of any from the top of my head).
We may check for the validity of children in some places where we do only allow a certain type of children, and then it is not necessarily about strict html validity, but also Juno-UI-Components architectural validity, but even there I doubt we are being 100% consistent tbh.
Short answer: In this case specifically we'd rather not do it., leave as is
The best we could do is display a React warning in the console OR throw an error and prevent the component from rendering. As a general rule we have decided against the latter and preserve some user responsibility. Also, users may choose to render a surrounding dl element themselves not using our component, and the result would be totally valid, we couldn't 100% detect that thus still emitting a warning.
|
|
||
| .dl { | ||
| display: grid; | ||
| grid-template-columns: 1fr 2fr; |
There was a problem hiding this comment.
Agreed, smth in the 25% to 30% range seems a good starting point.
We can add more complex behaviour later (https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/grid-template-columns).
There was a problem hiding this comment.
Basically what Esther said:
- use inline/tw-styles and remove external css
- fix default alignment of
dt - fix re-defining
--border-color-theme-default - update story wiht a few more
dt/ddterms to reflect a typical use case
plus removing any changes to Modal from this PR.
Thanks 🙏

Summary
Introduce a standardised
DescriptionListcomponent along with its child components,DescriptionTermandDescriptionDefinition, to display terms and descriptions consistently across applications following semantically correct HTML elements.DescriptionListwith child components #1172Changes Made
DescriptionList,DescriptionTerm, andDescriptionDefinitionComponents using corresponding html elements.DL,DT,DD) for easy use in React code, promoting cleaner and more readable syntax.Testing Instructions
Check ACs, Figma and test in Storybook.
Checklist
PR Manifesto
Review the PR Manifesto for best practises.