Skip to content

Commit 8a07290

Browse files
[#96] Use u-height-stretch instead of…
…u-height-100vh in sidebar #96
1 parent dd25114 commit 8a07290

8 files changed

Lines changed: 46 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
# Unreleased
4+
5+
## Breaking
6+
7+
- Sidebars use `u-height-strech` instead of `u-height-100vh`. This requires the project to run autoprefixer.
8+
If you can't run autoprefixer in your project, set `config :bitstyles_phoenix, autoprefixer: false` to get the
9+
old behaviour.
10+
311
## v2.1.1 - 2022-12-02
412

513
- Fixed version backwards compatibility

config/config.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Config
22

33
config :bitstyles_phoenix,
4-
trim_e2e_classes: [enabled: true]
4+
trim_e2e_classes: [enabled: true],
5+
autoprefixer: true
56

67
config :phoenix, :json_library, Jason

demo/config/config.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import Config
99

1010
config :bitstyles_phoenix,
1111
translate_errors: {BitstylesPhoenixDemoWeb.ErrorHelpers, :translate_error, []},
12-
icon_file: {BitstylesPhoenixDemoWeb.Endpoint, :static_path, ["/assets/images/icons.svg"]}
12+
icon_file: {BitstylesPhoenixDemoWeb.Endpoint, :static_path, ["/assets/images/icons.svg"]},
13+
autoprefixer: false
1314

1415
config :bitstyles_phoenix_demo, BitstylesPhoenixDemoWeb.Gettext,
1516
default_locale: "en",

demo/mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ defmodule BitstylesPhoenixDemo.MixProject do
7171
],
7272
bitstyles: [
7373
"cmd mkdir -p priv/static/assets",
74-
"cmd cp -R assets/node_modules/bitstyles/assets/* priv/static/assets"
74+
"cmd cp -R assets/node_modules/bitstyles/assets/* priv/static/assets",
75+
"cmd cp -R ../assets/logo.svg priv/static/assets/images/"
7576
],
7677
"bitstyles.watch": [
7778
"bitstyles",

lib/bitstyles_phoenix.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,20 @@ defmodule BitstylesPhoenix do
5353
5454
```elixir
5555
config :bitstyles_phoenix,
56-
bitstyles_version: "1.5.0"
56+
bitstyles_version: "3.0.0"
5757
```
5858
Release candidate versions are currently not supported.
5959
60+
### Autoprefixer
61+
62+
Bitstyles phoenix will use some classes that require autoprefixer even for newer browers.
63+
If you can't run autoprefixer for some reason (not recommended) you can set `autoprefixer: false`
64+
to make bitstyles_phoenix only output classes that are well supported in recent browsers.
65+
66+
```elixir
67+
config :bitstyles_phoenix, autoprefixer: false
68+
```
69+
6070
### Translating error messages
6171
6272
Generated phoenix apps usally come with a helper for [translating error messages](https://github.com/phoenixframework/phoenix/blob/496123b66c03c9764be623d2c32b4af611837eb0/installer/templates/phx_web/views/error_helpers.ex#L23-L46)

lib/bitstyles_phoenix/alpine3/sidebar.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ defmodule BitstylesPhoenix.Alpine3.Sidebar do
4949
...> </.ui_js_sidebar_layout>
5050
...> """
5151
"""
52-
<div class="u-flex u-height-100vh" x-data="{ sidebarOpen: false }">
52+
<div class="u-flex u-height-stretch" x-data="{ sidebarOpen: false }">
5353
<header role="banner" class="u-flex">
5454
<nav class="u-flex">
5555
<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">

lib/bitstyles_phoenix/bitstyles.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ defmodule BitstylesPhoenix.Bitstyles do
88
"#{@cdn_url}@#{@default_version}"
99
end
1010

11+
def autoprefixer do
12+
Application.get_env(:bitstyles_phoenix, :autoprefixer, true)
13+
end
14+
1115
@doc """
1216
Returns the classnames for the configured version.
1317
Input classnames are assumed to be from the #{@default_version} version of bitstyles.
@@ -25,6 +29,7 @@ defmodule BitstylesPhoenix.Bitstyles do
2529
mapping =
2630
case class do
2731
"u-border-radius-" <> variant -> "u-round-#{variant}"
32+
"u-height-stretch" -> "u-height-100vh"
2833
_ -> class
2934
end
3035

lib/bitstyles_phoenix/component/sidebar.ex

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defmodule BitstylesPhoenix.Component.Sidebar do
3838
...> </.ui_sidebar_layout>
3939
...> """
4040
"""
41-
<div class="u-flex u-height-100vh">
41+
<div class="u-flex u-height-stretch">
4242
<header role="banner" class="u-flex">
4343
<nav class="u-flex">
4444
<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">
@@ -200,7 +200,7 @@ defmodule BitstylesPhoenix.Component.Sidebar do
200200
...> </.ui_sidebar_layout>
201201
...> """
202202
"""
203-
<div class="u-flex u-height-100vh">
203+
<div class="u-flex u-height-stretch">
204204
<header role="banner" class="u-flex">
205205
<nav class="u-flex">
206206
<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">
@@ -238,7 +238,7 @@ defmodule BitstylesPhoenix.Component.Sidebar do
238238
...> </.ui_sidebar_layout>
239239
...> """
240240
"""
241-
<div class="u-flex u-height-100vh">
241+
<div class="u-flex u-height-stretch">
242242
<header role="banner" class="u-flex">
243243
<nav class="u-flex">
244244
<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">
@@ -297,7 +297,7 @@ defmodule BitstylesPhoenix.Component.Sidebar do
297297
assigns =
298298
assigns
299299
|> assign(
300-
class: classnames(["u-flex u-height-100vh", assigns[:class]]),
300+
class: classnames(["u-flex", wrapper_height(), assigns[:class]]),
301301
extra: extra,
302302
sidebar_extra: sidebar_extra,
303303
large_extra: large_extra,
@@ -425,4 +425,15 @@ defmodule BitstylesPhoenix.Component.Sidebar do
425425
<div class={@class} {@extra}><%= render_slot(@inner_block) %></div>
426426
"""
427427
end
428+
429+
defp wrapper_height() do
430+
# height: strech is not supported by recent browsers yet.
431+
# So if we can't have autoprefixer for some reason, we should
432+
# use height: 100vh.
433+
if BitstylesPhoenix.Bitstyles.autoprefixer() do
434+
"u-height-stretch"
435+
else
436+
"u-height-100vh"
437+
end
438+
end
428439
end

0 commit comments

Comments
 (0)