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

feat(NcButton): Introduce text and text-classes properties #4393

Closed
wants to merge 2 commits into from

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Aug 2, 2023

☑️ Resolves

Alternative for #4367

  • text is the visible text of the button, the default slot for passing the text is now deprecated
  • text-classes are additional classes injected to the text wrapper for custom styling
  • Added example when this should be used (for table headers)

So basically this moves from misused slot to text property with allowing to inject custom classes that can be used later for custom styling.
(Please note that I had to use the deprecated v-deep selector as vue-styleguidist does not support the recommended :deep selector).

🖼️ Screenshots

voko.mp4

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable

@susnux susnux added enhancement New feature or request 3. to review Waiting for reviews discussion Need advices, opinions or ideas on this topic feature: button labels Aug 2, 2023
@susnux susnux added this to the 8.0.0 milestone Aug 4, 2023
@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Aug 24, 2023
@skjnldsv
Copy link
Contributor

Conflicts

@susnux susnux force-pushed the fix/button-text branch 2 times, most recently from 71e675f to ad37789 Compare August 24, 2023 22:35
@susnux susnux added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Aug 24, 2023
@susnux
Copy link
Contributor Author

susnux commented Aug 24, 2023

@skjnldsv resolved


BTW I would prefer this one over #4367

marcoambrosini

This comment was marked as resolved.

const text = this.$slots.default?.[0]?.text?.trim?.()

/** @slot **deprecated** Use the `text` property instead */
const text = this.text || this.$slots.default?.[0]?.text?.trim?.()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we directly remove the slot in master which will be 8.x and introduce the deprecation for stable7?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be huge in terms of breaking projects, not sure if we want to do this already for version 8 or wait for the next

Copy link
Contributor

Choose a reason for hiding this comment

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

We have huge breaking changes in master already (e.g. the renaming from title to name) and the entire removal of some components. So, from my side, I wouldn't mind another breaking change.
The migration effort needs to be done anyway, the question is just, when does it suite you 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, we should either allow using slot for button content. It would also solve custom text formatting problem by allowing to pass formatted text as a markup.

<NcButton>
  <span class="foo">My text</span> <span class="down">🔻</span>
</NcButton>

Or remove the content slot at all and make this breaking change with text.

During beta we can add check to mounted that console.warn if slot is passed to help with the migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After seeing all of your validator fixes @ShGKme I think we should go with this one and only allow text content through props.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a commit that warns when the default slot is used as suggested by @ShGKme
Also added a test to remind us to remove that behavior when releasing (as soon as the version is set to stable it will fail if the default slot still works 😉 )

Copy link
Contributor

Choose a reason for hiding this comment

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

After seeing all of your validator fixes @ShGKme I think we should go with this one and only allow text content through props.

For the record, the only place where <button> had invalid non-phrasal content was User Menu avatar-button-trigger, and plain html <button> was used there. There was no HTML validation issue with NcButton content.


In general case, I'd definitely prefer to have a full-functional slot content (that allows actual content, not render-text function). But as no app actually needed any true custom content, we can use text. It would make component more performant and simple.

Alternatively, we may add a new slot, but explicitly mark it as a custom content slot, not the default text content.

src/components/NcButton/NcButton.vue Outdated Show resolved Hide resolved
src/components/NcButton/NcButton.vue Outdated Show resolved Hide resolved
src/components/NcButton/NcButton.vue Show resolved Hide resolved
* `text` is the visible text of the button, the default slot for passing the text is now deprecated
* `text-classes` are additional classes injected to the text wrapper for custom styling
* Added example when this should be used (for table headers)

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
…text

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Comment on lines +168 to +170
buttonText() {
return this.style.indexOf('text') !== -1 ? 'Example text' : ''
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
buttonText() {
return this.style.indexOf('text') !== -1 ? 'Example text' : ''
}
buttonText() {
return this.style.includes('text') ? 'Example text' : ''
}

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.

A huge painful breaking change but fine by me.

Let's wait for other opinions.

@susnux susnux requested a review from Pytal October 24, 2023 11:55
@susnux susnux closed this Nov 7, 2023
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 discussion Need advices, opinions or ideas on this topic enhancement New feature or request feature: button
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants