Created
March 10, 2022 21:40
-
-
Save Anthelmed/2d32f475b5a1647170cbcfab0de7cc49 to your computer and use it in GitHub Desktop.
Searchbar code example for the medium article on UIToolkit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ui:UXML> | |
<Style> | |
:root { | |
--search-bar-height: 40px; | |
--text-color: rgb(255, 255, 255); | |
--background-color: rgba(0, 0, 0, 0.8); | |
--animation-duration: 500ms; | |
} | |
.search-panel { | |
flex-direction: row; | |
height: 40px; | |
width: auto; | |
justify-content: flex-start; | |
margin-left: 10px; | |
margin-right: 10px; | |
margin-top: 10px; | |
margin-bottom: 10px; | |
} | |
.search-button { | |
-unity-font: url('project://database/Assets/MaterialIcons-Regular.ttf'); | |
-unity-font-definition: none; | |
width: var(--search-bar-height); | |
height: var(--search-bar-height); | |
color: var(--text-color); | |
font-size: 25px; | |
background-color: rgba(0, 0, 0, 0); | |
border-radius: 20px; | |
margin: 0; | |
padding: 0; | |
border-width: 0; | |
} | |
.search-field { | |
height: var(--search-bar-height); | |
width: 0; | |
color: rgba(255, 255, 255, 0); | |
background-color: rgba(0, 0, 0, 0); | |
margin: 0; | |
padding: 0; | |
padding-left: 8px; | |
-unity-text-align: middle-left; | |
border-width: 0; | |
font-size: 16px; | |
transition-property: all, color; | |
transition-duration: 0s, 250ms; | |
transition-timing-function: ease, linear; | |
transition-delay: 0s, 0s; | |
} | |
.search-background { | |
position: absolute; | |
width: var(--search-bar-height); | |
height: var(--search-bar-height); | |
background-color: var(--background-color); | |
border-radius: 20px; | |
transition-property: all, width; | |
transition-duration: 0s, var(--animation-duration); | |
transition-timing-function: ease, ease-in-out; | |
transition-delay: 0s, 0s; | |
} | |
.search-panel.open .search-field { | |
color: var(--text-color); | |
transition-property: all, color; | |
transition-duration: 0s, var(--animation-duration); | |
transition-timing-function: ease, linear; | |
transition-delay: 0s, var(--animation-duration); | |
} | |
.search-panel.open .search-background { | |
width: 120px; | |
transition-property: all, width; | |
transition-duration: 0s, var(--animation-duration); | |
transition-timing-function: ease, ease-out-back; | |
transition-delay: 0s, 0s; | |
} | |
</Style> | |
<ui:VisualElement name="Search-Panel" class="search-panel"> | |
<ui:VisualElement name="Search-background" class="search-background" /> | |
<ui:Button text="\ue8b6" name="Search-Button" class="search-button" /> | |
<ui:Label text="Search" name="Search-Field" class="search-field" /> | |
</ui:VisualElement> | |
</ui:UXML> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment