Sidebar
v0.0.10
mix mishka.ui.gen.component sidebar
About LiveView JS module commands
In the sidebar component, there are three attributes that allow users to execute custom LiveView JS commands when certain actions like showing or hiding occur. These attributes are:
- on_hide: This attribute lets the user execute an additional JavaScript command when the sidebar is hidden, alongside the default toggle action. For instance, a user might want to push some data to the server or trigger another function when the sidebar hides.
- on_show: This attribute allows you to run a custom JavaScript command when the sidebar is shown. Users can, for example, send data, log an event, or perform any other action when the sidebar is displayed.
- on_hide_away: This attribute allows for the execution of a JavaScript command when the sidebar is hidden by clicking outside of it. This could be useful for logging interactions or sending specific data back to the server.
These attributes give developers more control over the interactions with the sidebar, allowing for complex actions to be performed using custom JavaScript beyond just the default show/hide behavior.
Border prop
The border prop offers values like "extra_small", "small", "medium", "large", and "extra_large". Only Bordered and Outline variants can have border by default.
Border prop
<.sidebar id="unique_id" border="extra_small"></.sidebar>
<.sidebar id="unique_id" border="small"></.sidebar>
<.sidebar id="unique_id" border="medium"></.sidebar>
<.sidebar id="unique_id" border="large"></.sidebar>
<.sidebar id="unique_id" border="extra_large"></.sidebar>Size prop
The size prop allows developers to control the overall size of the sidebar component. It offers predefined values such as extra_small, small, medium, large, and extra_large, which adjust the width or height of the sidebar depending on its position. For sidebars positioned on the left or right of the screen, the prop adjusts the width, while for sidebars positioned at the top or bottom, it controls the height. This flexibility ensures the sidebar can fit various design requirements, making it adaptable for different content and use cases.
Size prop
<.sidebar id="unique_id" size="extra_small"></.sidebar>
<.sidebar id="unique_id" size="small"></.sidebar>
<.sidebar id="unique_id" size="medium"></.sidebar>
<.sidebar id="unique_id" size="large"></.sidebar>
<.sidebar id="unique_id" size="extra_large"></.sidebar>Position prop
The position prop supports values like start and end, with the default being start. Based on the text direction (LTR or RTL), this positions the sidebar at the start of the page.
Position prop
<.sidebar id="unique_id" position="start"></.sidebar>
<.sidebar id="unique_id" position="end"></.sidebar>Hide position prop
The hide_position attribute determines the direction the sidebar hides on mobile, with "left" sliding it off to the left and "right" sliding it off to the right for a smooth user experience.
Hide position prop
<.sidebar id="unique_id" hide_position="left"></.sidebar>
<.sidebar id="unique_id" hide_position="right"></.sidebar>On small devices
You can add the Sidebar.show_sidebar("unique_id", "hide_position") function to a button, allowing you to toggle the sidebar on smaller devices.
<button
phx-click={Sidebar.show_sidebar("unique_sidebar_id", "hide_position_value")}
>
Open Sidebar
</button>Minimize prop
Controls whether the minimize button is shown. Accepts a boolean value. Default is false.
Minimize prop
<.sidebar id="sidebar-minimize" minimize>
<:item
icon="hero-user"
icon_class="text-gray-500"
label="Profile"
label_class="text-sm text-gray-700"
link="/profile"
/>
<:item
icon="hero-bell"
icon_class="text-red-400"
label="Notifications"
label_class="font-medium"
link="/notifications"
/>
</.sidebar>Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
id
|
string
| — | — | Yes | A unique identifier is used to manage state and interaction |
variant
|
string
|
base
|
defaultoutlinetransparentborderedgradientbase
| No | Determines the style |
color
|
string
|
natural
|
basenaturalwhitedarkprimarysecondarysuccesswarningdangerinfosilvermiscdawn
| No | Determines color theme |
size
|
string
|
large
|
extra_smallsmallmediumlargeextra_large
| No | Determines the overall size of the elements, including padding, font size, and other items |
border
|
string
|
extra_small
| — | No | Determines border style |
minimize
|
boolean
|
false
| — | No | Determines Minimize button show or hide |
position
|
string
|
start
| — | No | Determines the element position |
hide_position
|
string
| — |
leftright
| No | Determines what position should be hidden, accepts "left" or "right" |
class
|
any
| — | — | No | Custom CSS class for additional styling |
hide_button_class
|
string
| — | — | No | Custom CSS class for additional styling |
minimize_wrapper_class
|
string
| — | — | No | Custom CSS class for additional styling |
close_wrapper_class
|
string
| — | — | No | Custom CSS class for additional styling |
content_class
|
string
| — | — | No | Custom CSS class for additional styling |
minimize_icon_class
|
string
| — | — | No | Custom CSS class for additional styling |
close_icon_class
|
string
| — | — | No | Custom CSS class for additional styling |
close_button_class
|
string
| — | — | No | Custom CSS class for additional styling for button |
list_wrapper_class
|
string
| — | — | No | Custom CSS class for additional to list wrapper |
on_hide
|
JS
| — | — | No | Custom JS module for on_hide action |
on_show
|
JS
| — | — | No | Custom JS module for on_show action |
on_hide_away
|
JS
| — | — | No | Custom JS module for on_hide_away action |
rest
|
global
| — | — | No | Global attributes can define defaults which are merged with attributes provided by the caller |
Slots
| Name | Required | Description |
|---|---|---|
item
| No | Menu item slot for sidebar navigation items |
inner_block
| No | Inner block that renders HEEx content |
Attributes of the item slot
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
icon
|
string
| — | — | No | Icon name to display |
icon_class
|
string
| — | — | No | CSS class for the icon |
label
|
string
| — | — | No | Text label for the menu item |
label_class
|
string
| — | — | No | CSS class for the label text |
link
|
string
| — | — | No | URL for the item link |
class
|
any
| — | — | No | CSS class for the entire item |
link_class
|
string
| — | — | No | CSS class for the link |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--variant
|
defaultoutlinetransparentborderedgradientbase
|
--color
|
basenaturalwhitedarkprimarysecondarysuccesswarningdangerinfosilvermiscdawn
|
--size
|
extra_smallsmallmediumlargeextra_large
|
--module
| A module name of your own |
What it generates
mix mishka.ui.gen.component sidebar