Skip to content
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

NcButton: Allow to format text of button #4367

Merged
merged 1 commit into from Nov 7, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Jul 26, 2023

☑️ Resolves

Allow us to format the text of a button without dirty hacks like :deep selectors, I added the example why this is useful and where we should use this: Table headers.

Places where we have this and can remove all custom hacks are: all file tables in the files app, the logreader app, the file picker.

⚠️ this is chained on #4366 (see first commit), should be reviewed and merged first

🖼️ Screenshots

image

🏁 Checklist

  • 📘 Component documentation has been extended, updated or is not applicable

@susnux susnux added enhancement New feature or request 3. to review Waiting for reviews feature: button labels Jul 26, 2023
Copy link
Contributor

@jancborchardt jancborchardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared to the normal buttons it seems like the text is a bit higher up here than there. Might be a non-issue since it’s only visible on hover / with background.

@susnux susnux force-pushed the feat/button-allow-span-in-content branch from 605976e to 2b12340 Compare July 27, 2023 09:06
Copy link
Contributor

@marcoambrosini marcoambrosini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for trailing icons, unless we have other use cases I would wrap the button component into a tableHeaderButton or something like that and make the style changes from there

@susnux
Copy link
Contributor Author

susnux commented Jul 27, 2023

Compared to the normal buttons it seems like the text is a bit higher up here than there. Might be a non-issue since it’s only visible on hover / with background.

Tested this with @szaimen on Window, it depends on your local font, we have a hack (1px margin) to center it with Segoe font which is aligned differently, but it breaks on other fonts (like I am using Roboto). See also #4200

@susnux susnux force-pushed the feat/button-allow-span-in-content branch from 2b12340 to 37ada1a Compare July 27, 2023 10:07
@ShGKme
Copy link
Contributor

ShGKme commented Jul 27, 2023

Same as for trailing icons, unless we have other use cases I would wrap the button component into a tableHeaderButton or something like that and make the style changes from there

We have many buttons in Talk with custom text styles: LeftSidbar, Settings button, Conversation, TopBar, CallTime and etc.

Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this change to allow custom content of the button (otherwise it should be a prop, not a slot).

But I'm not sure if it is the best way to customize text styles.

With this change, the usage of custom styles requires creating a new element just to set class:

<template>
  <NcButton class="my-button">
    <!-- There is no meaning in this span, only for setting a text's color -->
    <span class="my-button__text">Text</span>
  <NcButton>
</template>

<styles scoped>
.my-button__text {
  color: red;
}
</styles>

I'd prefer to have a prop to set inside styles or classes:

<template>
  <NcButton class="my-button" text-classes="my-button__text">
    Text
  <NcButton>
</template>

<styles scoped>
/* Also deep, but for my own classes, not NcButton's */
.my-button :deep(.my-button__text) {
  color: red;
}
</styles>

Or

<template>
  <NcButton class="my-button" text-styles="color: red">
    Text
  <NcButton>
</template>

@susnux
Copy link
Contributor Author

susnux commented Jul 28, 2023

I like the idea of having text-classes property, but than we should also deprecate the default slot. As than it is a misuse of Vue slots.
We probably should move to a text property instead.

@raimund-schluessler
Copy link
Contributor

Once this is merged, one way or the other, we could then also adjust these lines

.button-vue {
padding: 0 4px 0 16px;
&__wrapper {
flex-direction: row-reverse;
}
}

@susnux
Copy link
Contributor Author

susnux commented Sep 21, 2023

The more I think about this, the more I think we should went with this one.

Why? Because we use the pattern of the default slot = content everywhere. Only moving the Button to text property seems non consistent, while I personally prefer that idea.
Moreover the HTML <button> also allows every other content inside, so it feels more native.

@skjnldsv
Copy link
Contributor

skjnldsv commented Sep 22, 2023

I still don't get it. You can just set a class to the button and change the text styling? deep only works because there is a scoped css being used, but you are free to use standard css? I don't think we actually needs this, using :deep is not a hack, it's one way to ensure your css isn't scoped within a scoped <style>. Feel free to just use standard css?

I think we should keep things simple :)

Once this is merged, one way or the other, we could then also adjust these lines

src/components/NcBreadcrumb/NcBreadcrumb.vue#L339-L345

What does this do?
Put the icon at the end?
You can just use direction: rtl to adjust the text order and stay accessible

@susnux
Copy link
Contributor Author

susnux commented Sep 22, 2023

Basically the problem is: Either we should allow to put any content inside the button, like the native html button allows, including styling. Or we should add a way to apply custom styles or classes to the text wrapper.
Currently you can only apply a class to the whole button and then have to assume internals of the button component, see below.

using :deep is not a hack, it's one way to ensure your css isn't scoped within a scoped <style>

Yes but then you need to assume some internals of the button, and this is what you should not do.
Components should be a black box so that you do not depend on its implementation (because the class is assigned to the root element and not to the text wrapper).

You can just use direction: rtl to adjust the text order and stay accessible

No this is quite bad as you misuse it for stlying while you should use if for localization.


So a overall problem is missing consistancy with the components architecture. Sometimes you use the default slot for content and allow child nodes, sometimes a property. But for the button we use the slot but only allow text.
Meaning to be consistent we should either only allow text and then use a property together with a way to format that text, like the suggestes text-classes property, or allow any content within the button and simply use the default slot like it is done here.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux force-pushed the feat/button-allow-span-in-content branch from 37ada1a to 7ed4f4b Compare September 22, 2023 10:26
@skjnldsv
Copy link
Contributor

To make sure I get it right, the use case (not talking about the wider discussion) is just about reveting text and the icon, right?

@susnux
Copy link
Contributor Author

susnux commented Sep 23, 2023

To make sure I get it right, the use case (not talking about the wider discussion) is just about reveting text and the icon, right?

No that is already implement in 8.x by using the alignment variable.

It is about formatting the text, like color or weight. See the example added, it then can be used for the files list header (e.g. in files app or file picker) or for the log reader header. Simply speaking for every table header without to have using any hacks that depend on private internals of the component.

@susnux
Copy link
Contributor Author

susnux commented Oct 21, 2023

The more I think about this, the more I think we should went with this one.

After seeing all that validator issues @ShGKme fixes at the moment, maybe go with the alternative PR[1]. So that we do not allow arbitrary (and possibly wrong) content of the button but only text (and the icon).

What do you think?

[1] https://github.com/nextcloud-libraries/nextcloud-vue/pull/4393

@ShGKme
Copy link
Contributor

ShGKme commented Oct 23, 2023

deep only works because there is a scoped css being used, but you are free to use standard css? I don't think we actually needs this, using :deep is not a hack, it's one way to ensure your css isn't scoped within a scoped <style>. Feel free to just use standard css?

I think we should keep things simple :)

deep is a hack because it allows changing component's internal implementation (until we explicitly say that some class name is a part of the component's public interface and a way to customize it).

With deep any simple layout/class name refactoring brakes a layout.

@susnux
Copy link
Contributor Author

susnux commented Oct 30, 2023

As this seems to get more positive feedback than the alternative #4393

Shall we go with this one? 👍 | 👎 ?

@jancborchardt
Copy link
Contributor

@raimund-schluessler since you commented on the other one, what is your take here – approved or any feedback? :)

@susnux susnux requested a review from ShGKme November 7, 2023 10:29
@susnux
Copy link
Contributor Author

susnux commented Nov 7, 2023

Well then lets go with this one as it is less breaking?

@susnux susnux merged commit 946f14a into master Nov 7, 2023
15 checks passed
@susnux susnux deleted the feat/button-allow-span-in-content branch November 7, 2023 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request feature: button
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants