-
Notifications
You must be signed in to change notification settings - Fork 95
feat: add NcFormBoxButton #7779
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <script setup lang="ts"> | ||
| import type { Slot } from 'vue' | ||
| import type { VueClassType } from '../../utils/VueTypes.ts' | ||
|
|
||
| import { useNcFormBox } from '../../components/NcFormBox/useNcFormBox.ts' | ||
| import { createElementId } from '../../utils/createElementId.ts' | ||
| import { isLegacy } from '../../utils/legacy.ts' | ||
|
|
||
| defineOptions({ inheritAttrs: false }) | ||
|
|
||
| const { | ||
| tag, | ||
| label = undefined, | ||
| description = undefined, | ||
| invertedAccent = false, | ||
| class: rootClasses = undefined, | ||
| itemClasses = undefined, | ||
| } = defineProps<{ | ||
| /** Interactive item element's tag */ | ||
| tag: string | ||
| /** Main Label */ | ||
| label?: string | ||
| /** Optional description below the label, also used for the aria-describedby */ | ||
| description?: string | ||
| /** Accent on the description instead of the label */ | ||
| invertedAccent?: boolean | ||
| /** Root element classes */ | ||
| class?: VueClassType | ||
| /** Interactive item classes */ | ||
| itemClasses?: VueClassType | ||
| }>() | ||
|
|
||
| defineEmits<{ | ||
| /** Click on the item */ | ||
| click: [event: MouseEvent] | ||
| }>() | ||
|
|
||
| const slots = defineSlots<{ | ||
| /** Item's label custom content */ | ||
| default?: Slot<{ | ||
| /** IDRef of the description element if present */ | ||
| descriptionId?: string | ||
| }> | ||
| /** Custom description content */ | ||
| description?: Slot<{ | ||
| /** IDRef of the description element if present */ | ||
| descriptionId?: string | ||
| }> | ||
| /** Icon content */ | ||
| icon?: Slot | ||
| }>() | ||
|
|
||
| const { formBoxItemClass } = useNcFormBox() | ||
|
|
||
| const descriptionId = createElementId() | ||
| const hasDescription = () => !!description || !!slots.description | ||
Antreesy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </script> | ||
|
|
||
| <template> | ||
| <div | ||
| :class="[ | ||
| rootClasses, | ||
| $style.formBoxItem, | ||
| formBoxItemClass, | ||
| { | ||
| [$style.formBoxItem_inverted]: invertedAccent && hasDescription(), | ||
| [$style.formBoxItem_legacy]: isLegacy, | ||
| }, | ||
| ]"> | ||
| <span :class="$style.formBoxItem__content"> | ||
| <component | ||
| :is="tag" | ||
| :class="[$style.formBoxItem__element, itemClasses]" | ||
| v-bind="$attrs" | ||
| @click="$emit('click', $event)"> | ||
Antreesy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <slot :description-id> | ||
| {{ label || '⚠️ Label is missing' }} | ||
| </slot> | ||
| </component> | ||
| <span v-if="hasDescription()" :id="descriptionId" :class="$style.formBoxItem__description"> | ||
| <slot name="description"> | ||
| {{ description }} | ||
| </slot> | ||
| </span> | ||
| </span> | ||
| <span :class="$style.formBoxItem__icon"> | ||
| <slot name="icon" :description-id> | ||
| ⚠️ Icon is missing | ||
| </slot> | ||
| </span> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style lang="scss" module> | ||
| .formBoxItem { | ||
| --nc-form-box-item-border-width: 1px; | ||
| --nc-form-box-item-min-height: 40px; // Special size defined by the design | ||
| --form-element-label-offset: calc(var(--border-radius-element) + var(--default-grid-baseline)); | ||
| --form-element-label-padding: calc(var(--form-element-label-offset) - var(--nc-form-box-item-border-width)); | ||
| // New colors we don't yet have in theming | ||
| // TODO: add new colors to the theming | ||
| --color-primary-element-extra-light: hsl(from var(--color-primary-element-light) h s calc(l * 1.045)); | ||
| --color-primary-element-extra-light-hover: hsl(from var(--color-primary-element-light-hover) h s calc(l * 1.045)); | ||
| position: relative; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: calc(2 * var(--default-grid-baseline)); | ||
| min-height: var(--nc-form-box-item-min-height); | ||
| padding-inline: var(--form-element-label-padding); | ||
| border: 1px solid var(--color-primary-element-extra-light-hover); | ||
| border-bottom-width: 2px; | ||
| border-radius: var(--border-radius-element); | ||
| background-color: var(--color-primary-element-extra-light); | ||
| color: var(--color-primary-element-light-text); | ||
| transition-property: color, border-color, background-color; | ||
| transition-duration: var(--animation-quick); | ||
| transition-timing-function: linear; | ||
| user-select: none; | ||
| cursor: pointer; | ||
|
|
||
| * { | ||
| cursor: inherit; | ||
| } | ||
|
|
||
| &:has(:disabled) { | ||
Antreesy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cursor: default; | ||
| opacity: 0.5; | ||
| } | ||
|
|
||
| &:hover:not(:has(:disabled)) { | ||
| color: var(--color-primary-element-light-text); | ||
| background-color: var(--color-primary-element-extra-light-hover); | ||
| } | ||
|
|
||
| &:has(:focus-visible) { | ||
| outline: 2px solid var(--color-main-text); | ||
| box-shadow: 0 0 0 4px var(--color-main-background); | ||
| } | ||
|
|
||
| &.formBoxItem_legacy { | ||
| --nc-form-box-item-border-width: 0px; | ||
| border: none; | ||
| } | ||
|
|
||
| &.formBoxItem_inverted { | ||
| .formBoxItem__element { | ||
| color: var(--color-text-maxcontrast); | ||
| } | ||
|
|
||
| .formBoxItem__description { | ||
| color: inherit; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .formBoxItem__content { | ||
| flex: 1; | ||
| display: flex; | ||
| flex-direction: column; | ||
| padding-block: calc(2 * var(--default-grid-baseline)); | ||
| overflow-wrap: anywhere; | ||
| } | ||
|
|
||
| // A trick for accessibility: | ||
| // make entire component clickable while internally splitting the interactive item and the description | ||
| .formBoxItem__element::after { | ||
| content: ''; | ||
| position: absolute; | ||
| inset: 0; | ||
| } | ||
|
|
||
| .formBoxItem__description { | ||
| color: var(--color-text-maxcontrast); | ||
| } | ||
|
|
||
| .formBoxItem__icon { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: flex-end; | ||
| } | ||
| </style> | ||
|
|
||
| <docs> | ||
| An internal component | ||
| </docs> | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
new folder structure? Why not put it inside
components/NcFormBox/like we do with some other shared components?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.
To make it clear that it is not a public API and prevent "I forgot to exclude from the docs" situations.
But it is an internal thing, so we can refactor the structure any moment later.
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.
Is there anything Public API/design/implementation related?
Since this is the only one comment in the review, I don't know, if it is the full review or you submitted with this comment only
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.
No otherwise its fine!
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.
But only what is exported from the
index.tsis public API.IMHO having a new folder structure is more confusing than helpful.
True but thats due to non-explicitly defined styleguidist config but also not hard to add.
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.
So I would prefer moving it in this PR back to the normal location
/src/components/NcFormBox/NcFormBoxItem.vueand do a follow up where we e.g. move all internal components and composables to consistent new locations. So we can just continue this one without mixing build related changes.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.
Even if we call
components/NAME/NAME.vuepublic, it doesn't specify the position for the private component, does it? Works if it is a subcomponent of a specific public one, but what if it is shared?components/Foo/Foo.vue-> uses ->Shared.vuecomponents/Bar/Bar.vue-> uses ->Shared.vueOk,
Foo.vueandBar.vueare public. WhereShared.vueis supposed to be?If in Foo - why not Bar. If in Bar - why not Foo.
The following components are "every other" and they are public:
components/NcRichContenteditable/NcMentionBubble.vuecomponents/NcRichContenteditable/NcAutoCompleteResult.vueSo:
publicprivateeven if p.1 were actualThere 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.
It does matter a lot. In a private component I can do everything, rewrite it, rename, change the interface, throw it away. In a public component I need to be careful and not break anything. It is easy to change it and hard to bring back after being released.
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.
I also proposed 2 alternative names for the folder and 1 alternative location.
Again, I'm fine with a different location, folder name or both.
I'm not fine with just mixing public with private files together and only separate by including/excluding in re-export and the list on the docs.
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.
@susnux I pushed a commit moving the component to the
components/NcFormBox/NcFormBoxItem.vue. I don't think this is the best place for it, but it can be discussed later, outside theNcFormBoxButtonPR.