kirbydesign / designsystem

Kirby Design System
https://cookbook.kirby.design
MIT License
85 stars 23 forks source link

[RESEARCH] Desktop ready general solution for hover state #1866

Closed RasmusKjeldgaard closed 2 years ago

RasmusKjeldgaard commented 3 years ago

Describe why and what should be researched

As part of the work of making the Kirby Components Desktop Ready, it would make sense to research if it is possible to make general solutions for various interactivity states, before beginning implementing component specific solutions. This issue is concerned with hover/cursor (pointer/hand/mickey-mouse-thingy).

Considerations

The following is worth considering when researching

Design:

Implementation:

Other

Describe the goal

To unearth problems and consider if it is possible to come up with a (potentially partially) general solution for implementing the interactivity state. If possible also a POC of the solution.

MadsBuchmann commented 3 years ago

Timebox: 3 days

jkaltoft commented 2 years ago

💡 Findings

I'll pursue the following ideas to see if they hold:

  1. Never use :hover directly in Kirby components
  2. Use the hover() mixin everywhere you would use :hover

On the other hand, the hover() mixin uses a content block (@content). We probably need a utility that will apply whatever styles we declare for hover, e.g.:

// Utility
@mixin apply-hover() {
    @include hover() {
        // Declare styles for hover in general
    }
}

// Usage
button {
    @include apply-hover();
}

Optionally apply-hover() could take an argument that determines how "loud" changing interaction state should be, e.g. @include apply-hover(700) or @include apply-hover(400) or similar - kind of like the attention levels. The numbers indicate the "loudness" using a scale similar to CSS font-weight.

Another detail to consider is: Should the existing hover() mixin be extended to not apply to disabled elements?:

@mixin hover {
    &:not([disabled]):hover {
        @content;
    }
}
jkaltoft commented 2 years ago

📝 Tasks

Refactor usage of hover() mixin - use apply-hover()

  1. Create new utility/mixin apply-hover()
  2. Refactor components - use apply-hover()
    • Button
    • Chip
  3. Look for other components where we should use apply-hover()
  4. Consider removing hover() mixin completely

This may require decomposition of hover as a concept, e.g. into:

We could create multiple - possibly private/non-exposed - utilities/mixins for this, e.g.

@mixin apply-elevation {
    // declare background color
    // declare border
    // declare box-shadow
}

@apply-hover() {
    @include apply-elevation();
    // include other mixins and properties that defines what hover means in Kirby
    cursor: pointer;
}
jkaltoft commented 2 years ago

A slightly different approach has been decided. Create a solution based on Material Design's state layers (#1935). See PoC Codepen.