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

Upgrade bitstyles to 5.0.1 #125

Merged
merged 20 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Basic helpers for [bitstyles](https://github.com/bitcrowd/bitstyles) for elixir

Bitstyles must be installed separately into the asset generation. The helpers in this project just output classes for working with bitstyles.

Bitstyles versions from 4.3.0 down to 1.3.0 are supported.
Bitstyles versions from 5.0.1 down to 1.3.0 are supported.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion lib/bitstyles_phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule BitstylesPhoenix do

```elixir
<.ui_badge>A nice badge</.ui_badge>
# => <span class="a-badge u-h6 u-font-medium a-badge--gray">A nice badge</span>
# => <span class="a-badge u-h6 u-font-medium a-badge--text">A nice badge</span>
```

```elixir
Expand Down
16 changes: 8 additions & 8 deletions lib/bitstyles_phoenix/alpine3/dropdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule BitstylesPhoenix.Alpine3.Dropdown do
'''
"""
<div class="u-relative" x-data="{ dropdownOpen: false }">
<button type="button" @click="dropdownOpen = true" class="a-button a-button--ui">
<button type="button" @click="dropdownOpen = true" class="a-button a-button--secondary">
<span class="a-button__label">
Select me
</span>
Expand All @@ -56,14 +56,14 @@ defmodule BitstylesPhoenix.Alpine3.Dropdown do
</use>
</svg>
</button>
<ul class="a-dropdown u-overflow-y-auto a-list-reset u-margin-s-top" @click.away="dropdownOpen = false" x-cloak="x-cloak" x-show="dropdownOpen" x-transition:enter="is-transitioning" x-transition:enter-end="is-on-screen" x-transition:enter-start="is-off-screen" x-transition:leave="is-transitioning" x-transition:leave-end="is-off-screen" x-transition:leave-start="is-on-screen">
<ul class="a-dropdown u-overflow-y-auto u-list-none u-margin-s-top" @click.away="dropdownOpen = false" x-cloak="x-cloak" x-show="dropdownOpen" x-transition:enter="is-transitioning" x-transition:enter-end="is-on-screen" x-transition:enter-start="is-off-screen" x-transition:leave="is-transitioning" x-transition:leave-end="is-off-screen" x-transition:leave-start="is-on-screen">
<li>
<a href="#" class="a-button a-button--menu u-h6">
<a href="#" class="a-button a-button--transparent a-button--menu u-h6">
Option 1
</a>
</li>
<li>
<a href="#" class="a-button a-button--menu u-h6">
<a href="#" class="a-button a-button--transparent a-button--menu u-h6">
Option 2
</a>
</li>
Expand Down Expand Up @@ -103,7 +103,7 @@ defmodule BitstylesPhoenix.Alpine3.Dropdown do
'''
"""
<div class="u-relative" x-data="{ myOwnDropDown: false }">
<button type="button" @click="myOwnDropDown = true" class="a-button a-button--ui">
<button type="button" @click="myOwnDropDown = true" class="a-button a-button--secondary">
<span class="a-button__label">
Select me
</span>
Expand All @@ -112,14 +112,14 @@ defmodule BitstylesPhoenix.Alpine3.Dropdown do
</use>
</svg>
</button>
<ul class="a-dropdown u-overflow-y-auto a-list-reset u-margin-s-top" @click.away="myOwnDropDown = false" x-cloak="x-cloak" x-show="myOwnDropDown" x-transition:enter="is-transitioning" x-transition:enter-end="is-on-screen" x-transition:enter-start="is-off-screen" x-transition:leave="is-transitioning" x-transition:leave-end="is-off-screen" x-transition:leave-start="is-on-screen">
<ul class="a-dropdown u-overflow-y-auto u-list-none u-margin-s-top" @click.away="myOwnDropDown = false" x-cloak="x-cloak" x-show="myOwnDropDown" x-transition:enter="is-transitioning" x-transition:enter-end="is-on-screen" x-transition:enter-start="is-off-screen" x-transition:leave="is-transitioning" x-transition:leave-end="is-off-screen" x-transition:leave-start="is-on-screen">
<li>
<a href="#" class="a-button a-button--menu u-h6">
<a href="#" class="a-button a-button--transparent a-button--menu u-h6">
Option 1
</a>
</li>
<li>
<a href="#" class="a-button a-button--menu u-h6">
<a href="#" class="a-button a-button--transparent a-button--menu u-h6">
Option 2
</a>
</li>
Expand Down
24 changes: 12 additions & 12 deletions lib/bitstyles_phoenix/alpine3/sidebar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ defmodule BitstylesPhoenix.Alpine3.Sidebar do
...> </:small_sidebar>
...> <:sidebar_content>
...> <.ui_sidebar_nav>
...> <.ui_sidebar_nav_item><.ui_button href="#" class="u-flex-grow-1" variant="nav">Menu item #1</.ui_button></.ui_sidebar_nav_item>
...> <.ui_sidebar_nav_item><.ui_button href="#" class="u-flex-grow-1" variant="nav">Menu item #2</.ui_button></.ui_sidebar_nav_item>
...> <.ui_sidebar_nav_item><.ui_button href="#" class="u-flex-grow-1" color="transparent">Menu item #1</.ui_button></.ui_sidebar_nav_item>
...> <.ui_sidebar_nav_item><.ui_button href="#" class="u-flex-grow-1" color="transparent">Menu item #2</.ui_button></.ui_sidebar_nav_item>
...> </.ui_sidebar_nav>
...> </:sidebar_content>
...> <:main :let={s} class="u-margin-s-top">
Expand All @@ -54,27 +54,27 @@ defmodule BitstylesPhoenix.Alpine3.Sidebar do
<div class="u-flex u-height-100vh" x-data="{ sidebarOpen: false }">
<header role="banner" class="u-flex">
<nav class="u-flex">
<div class="u-hidden o-sidebar--large u-flex-shrink-0 u-padding-m-top u-flex@l u-flex-col u-bg-gray-80 u-fg-gray-30">
<div class="u-hidden o-sidebar--large u-flex-shrink-0 u-padding-m-top u-flex@l u-flex-col u-bg-gray-darker u-fg-text">
<a href="#" class="u-padding-l">
<img src="assets/logo.svg" aria-hidden="true" width="100"/>
<span class="u-sr-only">
bitcrowd
</span>
</a>
<ul class="u-flex-grow-1 u-flex-shrink-1 u-overflow-y-auto a-list-reset u-flex u-flex-col u-items-stretch u-padding-xs-right u-padding-xs-left">
<ul class="u-flex-grow-1 u-flex-shrink-1 u-overflow-y-auto u-list-none u-flex u-flex-col u-items-stretch u-padding-xs-right u-padding-xs-left">
<li class="u-margin-xs-bottom u-flex">
<a href="#" class="a-button a-button--nav u-flex-grow-1">
<a href="#" class="a-button a-button--transparent u-flex-grow-1">
Menu item #1
</a>
</li>
<li class="u-margin-xs-bottom u-flex">
<a href="#" class="a-button a-button--nav u-flex-grow-1">
<a href="#" class="a-button a-button--transparent u-flex-grow-1">
Menu item #2
</a>
</li>
</ul>
</div>
<div class="o-sidebar--small u-flex u-flex-col u-hidden@l u-bg-gray-80 u-fg-gray-30" @click.away="sidebarOpen = false" id="sidebar-small" x-cloak="x-cloak" x-show="sidebarOpen" x-transition:enter="is-transitioning" x-transition:enter-end="is-on-screen" x-transition:enter-start="is-off-screen" x-transition:leave="is-transitioning" x-transition:leave-end="is-off-screen" x-transition:leave-start="is-on-screen">
<div class="o-sidebar--small u-flex u-flex-col u-hidden@l u-bg-gray-darker u-fg-text" @click.away="sidebarOpen = false" id="sidebar-small" x-cloak="x-cloak" x-show="sidebarOpen" x-transition:enter="is-transitioning" x-transition:enter-end="is-on-screen" x-transition:enter-start="is-off-screen" x-transition:leave="is-transitioning" x-transition:leave-end="is-off-screen" x-transition:leave-start="is-on-screen">
<div class="u-flex">
<a href="#" class="u-flex-grow-1 u-padding-l">
<img src="assets/logo.svg" aria-hidden="true" width="100"/>
Expand All @@ -83,7 +83,7 @@ defmodule BitstylesPhoenix.Alpine3.Sidebar do
</span>
</a>
<div>
<button type="button" :aria-expanded="sidebarOpen" @click="sidebarOpen = false" aria-controls="sidebar-small" class="a-button a-button--icon a-button--icon-reversed" title="Close">
<button type="button" :aria-expanded="sidebarOpen" @click="sidebarOpen = false" aria-controls="sidebar-small" class="a-button a-button--square" data-theme="dark" title="Close">
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="a-icon" focusable="false" height="16" width="16">
<use xlink:href="#icon-cross">
</use>
Expand All @@ -94,14 +94,14 @@ defmodule BitstylesPhoenix.Alpine3.Sidebar do
</button>
</div>
</div>
<ul class="u-flex-grow-1 u-flex-shrink-1 u-overflow-y-auto a-list-reset u-flex u-flex-col u-items-stretch u-padding-xs-right u-padding-xs-left">
<ul class="u-flex-grow-1 u-flex-shrink-1 u-overflow-y-auto u-list-none u-flex u-flex-col u-items-stretch u-padding-xs-right u-padding-xs-left">
<li class="u-margin-xs-bottom u-flex">
<a href="#" class="a-button a-button--nav u-flex-grow-1">
<a href="#" class="a-button a-button--transparent u-flex-grow-1">
Menu item #1
</a>
</li>
<li class="u-margin-xs-bottom u-flex">
<a href="#" class="a-button a-button--nav u-flex-grow-1">
<a href="#" class="a-button a-button--transparent u-flex-grow-1">
Menu item #2
</a>
</li>
Expand All @@ -111,7 +111,7 @@ defmodule BitstylesPhoenix.Alpine3.Sidebar do
</header>
<main class="u-flex-grow-1 u-overflow-y-auto u-margin-s-top">
<div class="a-content flex">
<button type="button" :aria-expanded="sidebarOpen" @click="sidebarOpen = true" aria-controls="sidebar-small" class="a-button a-button--icon u-hidden@l u-margin-s-right" title="Open sidebar">
<button type="button" :aria-expanded="sidebarOpen" @click="sidebarOpen = true" aria-controls="sidebar-small" class="a-button a-button--square u-hidden@l u-margin-s-right" title="Open sidebar">
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="a-icon" focusable="false" height="16" width="16">
<use xlink:href="#icon-hamburger">
</use>
Expand Down
47 changes: 43 additions & 4 deletions lib/bitstyles_phoenix/bitstyles.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule BitstylesPhoenix.Bitstyles do
@moduledoc false

@default_version "4.3.0"
@default_version "5.0.1"
@cdn_url "https://cdn.jsdelivr.net/npm/bitstyles"

def cdn_url do
Expand All @@ -14,12 +14,51 @@ defmodule BitstylesPhoenix.Bitstyles do
"""
def classname(name), do: classname(name, version())

def classname(class, version) when version > "4.3.0" do
def classname(class, version) when version > "5.0.1" do
IO.warn("Version #{version} of bitstyles is not yet supported")
class
end

def classname(class, version) when version >= "4.2.0", do: class
def classname(class, version) when version >= "5.0.0" do
class
end

def classname(class, version) when version >= "4.2.0" do
sizes_renaming = %{
"3xs" => "xxxs",
"2xs" => "xxs",
"2xl" => "xxl",
"3xl" => "xxxl"
}

class =
Enum.reduce(sizes_renaming, class, fn {new_size, old_size}, acc ->
String.replace(acc, "-#{new_size}", "-#{old_size}")
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we at least make sure here, that the class starts with u- and is a bitstyles class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

end)

border_color_renaming = %{
"u-border-gray-light" => "u-border-gray-10",
"u-border-gray-dark" => "u-border-gray-70"
}

class =
Enum.reduce(border_color_renaming, class, fn {new_border_color, old_border_color}, acc ->
String.replace(acc, new_border_color, old_border_color)
end)

class =
case class do
"u-list-none" -> "a-list-reset"
"a-badge--text" -> "a-badge--gray"
"u-gap-l" -> "u-gap-m"
Copy link
Member

@andreasknoepfle andreasknoepfle Jul 8, 2024

Choose a reason for hiding this comment

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

🤔 this will change the behaviour quite a lot, right? We have numerous places in the code in dima e.g. that use u-gap-l already. They will all be using u-gap-m afterwards if they pass through this. But there is also only one bitstyles helper using u-gap-m. Mabye we can instead simply list this as a change for ui_dl_item, since one can always pass in an overriding u-gap-l into the classes and not add this migration here.
After all size can also be maintained by setting the gap size in sass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand...

We have numerous places in the code in dima e.g. that use u-gap-l already. They will all be using u-gap-m afterwards if they pass through this.

Isn't this exactly what we want? The class u-gap-m is 4.3.0 has the same styles as u-gap-l in 5.0.0. The name of the class changed, but the exactly rem value used for the gap remained the same.

Copy link
Member

Choose a reason for hiding this comment

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

But then are the values for u-gap-m and u-gap-l then same value by default now?
What I am saying is also that we do not make an assumption on the "migratedness" of foreign code that uses the helpers. With this setting you basically can't use u-gap-l anymore with bistyles 4.3.0 even if you want to have that value if you have classes going through this helper.

Copy link
Member

Choose a reason for hiding this comment

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

Also keep in mind the values are always just values set by the sass variables, so one can always go back to the old values if they want to not migrate things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But then are the values for u-gap-m and u-gap-l then same value by default now?

The class u-gap-m does not exist in the default configuration of bitstyles in 5.0.0, see:

https://github.com/bitcrowd/bitstyles/blob/v5.0.1/scss/bitstyles/utilities/gap/_settings.scss#L4-L7

What I am saying is also that we do not make an assumption on the "migratedness" of foreign code that uses the helpers. With this setting you basically can't use u-gap-l anymore with bistyles 4.3.0 even if you want to have that value if you have classes going through this helper.

I think I understand. It's fine to define class mappings in this module if the new class only exists in the new version, and the old class only exists in the old version. But here we have a new class that exists in both new and old version, but with a different meaning in the old version (u-gap-l from 4.3.0 would be equivalent to u-gap-xl in 5.0.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"u-fg-text" -> "u-fg-gray-30"
"u-fg-text-darker" -> "u-fg-gray-50"
"u-bg-gray-darker" -> "u-bg-gray-80"
class -> class
end

classname(class, "5.0.0")
end

def classname(class, version) when version >= "4.0.0" do
mapping =
Expand All @@ -28,7 +67,7 @@ defmodule BitstylesPhoenix.Bitstyles do
_ -> class
end

classname(mapping, "4.2.0")
classname(mapping, "4.3.0")
end

def classname(class, version) when version >= "2.0.0" do
Expand Down
16 changes: 8 additions & 8 deletions lib/bitstyles_phoenix/component/avatar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ defmodule BitstylesPhoenix.Component.Avatar do
'''
iex> assigns = %{}
...> render ~H"""
...> <.ui_avatar src="https://placekitten.com/100/100" alt="Username’s avatar"/>
...> <.ui_avatar src="https://placehold.co/100x100" alt="Username’s avatar"/>
...> """
''',
'''
"""
<div class="u-flex u-items-center">
<div class="a-avatar">
<img height="32" width="32" alt="Username’s avatar" src="https://placekitten.com/100/100"/>
<img height="32" width="32" alt="Username’s avatar" src="https://placehold.co/100x100"/>
</div>
</div>
"""
Expand All @@ -38,14 +38,14 @@ defmodule BitstylesPhoenix.Component.Avatar do
'''
iex> assigns = %{}
...> render ~H"""
...> <.ui_avatar src="https://placekitten.com/100/100" class="foo bar" alt="Username’s avatar"/>
...> <.ui_avatar src="https://placehold.co/100x100" class="foo bar" alt="Username’s avatar"/>
...> """
''',
'''
"""
<div class="u-flex u-items-center">
<div class="a-avatar foo bar">
<img height="32" width="32" alt="Username’s avatar" src="https://placekitten.com/100/100"/>
<img height="32" width="32" alt="Username’s avatar" src="https://placehold.co/100x100"/>
</div>
</div>
"""
Expand All @@ -57,14 +57,14 @@ defmodule BitstylesPhoenix.Component.Avatar do
'''
iex> assigns = %{}
...> render ~H"""
...> <.ui_avatar size="l" src="https://placekitten.com/100/100" alt="Username’s avatar" height="46" width="46"/>
...> <.ui_avatar size="l" src="https://placehold.co/100x100" alt="Username’s avatar" height="46" width="46"/>
...> """
''',
'''
"""
<div class="u-flex u-items-center">
<div class="a-avatar a-avatar--l">
<img alt="Username’s avatar" height="46" src="https://placekitten.com/100/100" width="46"/>
<img alt="Username’s avatar" height="46" src="https://placehold.co/100x100" width="46"/>
</div>
</div>
"""
Expand All @@ -76,14 +76,14 @@ defmodule BitstylesPhoenix.Component.Avatar do
'''
iex> assigns = %{}
...> render ~H"""
...> <.ui_avatar src="https://placekitten.com/100/100" alt="Username’s avatar"> Username </.ui_avatar>
...> <.ui_avatar src="https://placehold.co/100x100" alt="Username’s avatar"> Username </.ui_avatar>
...> """
''',
'''
"""
<div class="u-flex u-items-center">
<div class="a-avatar">
<img height="32" width="32" alt="Username’s avatar" src="https://placekitten.com/100/100"/>
<img height="32" width="32" alt="Username’s avatar" src="https://placehold.co/100x100"/>
</div>
<span class="u-margin-s-left">
Username
Expand Down
13 changes: 10 additions & 3 deletions lib/bitstyles_phoenix/component/badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ defmodule BitstylesPhoenix.Component.Badge do
...> </.ui_badge>
...> """
''',
'''
"5.0.1": '''
"""
<span class="a-badge u-h6 u-font-medium a-badge--text">
published
</span>
"""
''',
"4.3.0": '''
"""
<span class="a-badge u-h6 u-font-medium a-badge--gray">
published
Expand Down Expand Up @@ -105,15 +112,15 @@ defmodule BitstylesPhoenix.Component.Badge do
''',
'''
"""
<span class="a-badge u-h6 u-font-medium a-badge--gray extra-class" data-foo="bar">
<span class="a-badge u-h6 u-font-medium a-badge--text extra-class" data-foo="bar">
published
</span>
"""
'''
)

def ui_badge(assigns) do
variant = assigns[:variant] || "gray"
variant = assigns[:variant] || "text"

class =
classnames([
Expand Down
Loading
Loading