userbar.scss 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. @use 'sass:map';
  2. @use 'sass:math';
  3. @use 'sass:string';
  4. @tailwind base;
  5. @tailwind components;
  6. @import '../../../../../client/scss/settings';
  7. @import '../../../../../client/scss/tools';
  8. // =============================================================================
  9. // Variables
  10. // =============================================================================
  11. $size-home-button: 3.5em;
  12. $position: 2em;
  13. $width-arrow: 0.6em;
  14. $box-shadow-props: 0 0 1px 0 rgba(107, 214, 230, 1),
  15. 0 1px 10px 0 rgba(107, 214, 230, 0.7);
  16. $max-items: 12;
  17. $userbar-radius: 6px;
  18. // Possible positions for the userbar to exist in. These are set through the
  19. // {% wagtailuserbar 'bottom-left' %} template tag.
  20. $positions: (
  21. 'top-left': (
  22. 'vertical': 'top',
  23. 'horizontal': 'left',
  24. 'arrow': 'bottom',
  25. ),
  26. 'top-right': (
  27. 'vertical': 'top',
  28. 'horizontal': 'right',
  29. 'arrow': 'bottom',
  30. ),
  31. 'bottom-left': (
  32. 'vertical': 'bottom',
  33. 'horizontal': 'left',
  34. 'arrow': 'top',
  35. ),
  36. 'bottom-right': (
  37. 'vertical': 'bottom',
  38. 'horizontal': 'right',
  39. 'arrow': 'top',
  40. ),
  41. );
  42. // =============================================================================
  43. // Wagtail userbar proper
  44. // =============================================================================
  45. .w-userbar {
  46. position: fixed;
  47. z-index: 9999;
  48. font-size: initial;
  49. line-height: initial;
  50. margin: 0;
  51. padding: 0;
  52. // Stop hiding the userbar once stylesheets are loaded.
  53. // stylelint-disable-next-line declaration-no-important
  54. display: block !important;
  55. border: 0;
  56. width: auto;
  57. height: auto;
  58. &-icon {
  59. @include svg-icon(2em);
  60. }
  61. }
  62. @media print {
  63. .w-userbar {
  64. display: none;
  65. }
  66. }
  67. .w-userbar-trigger {
  68. display: flex;
  69. align-items: center;
  70. justify-content: center;
  71. width: $size-home-button;
  72. height: $size-home-button;
  73. margin: 0;
  74. overflow: hidden;
  75. background-color: $color-white;
  76. border: 2px solid transparent;
  77. border-radius: 50%;
  78. color: $color-black;
  79. padding: 0;
  80. cursor: pointer;
  81. box-shadow: $box-shadow-props;
  82. transition: all 0.2s ease-in-out;
  83. font-size: 1rem;
  84. text-decoration: none;
  85. position: relative;
  86. .w-userbar-help-text {
  87. // Visually hide the help text
  88. clip: rect(0 0 0 0);
  89. clip-path: inset(50%);
  90. height: 1px;
  91. overflow: hidden;
  92. position: absolute;
  93. white-space: nowrap;
  94. width: 1px;
  95. }
  96. .w-icon:before {
  97. transition: color 0.2s ease;
  98. font-size: 2rem;
  99. width: auto;
  100. margin: 0;
  101. }
  102. &:focus {
  103. outline: $color-focus-outline solid 3px;
  104. }
  105. }
  106. .w-userbar-items {
  107. display: block;
  108. list-style: none;
  109. position: absolute;
  110. margin: 0;
  111. min-width: 210px;
  112. visibility: hidden;
  113. font-family: $font-sans;
  114. font-size: 0.875rem;
  115. padding-inline-start: 0;
  116. text-decoration: none;
  117. .w-userbar.is-active & {
  118. visibility: visible;
  119. }
  120. }
  121. // Arrow
  122. .w-userbar-items:after {
  123. content: '';
  124. position: absolute;
  125. width: 0;
  126. height: 0;
  127. opacity: 0;
  128. border: solid $width-arrow transparent;
  129. transition-duration: 0.15s;
  130. transition-timing-function: cubic-bezier(0.55, 0, 0.1, 1);
  131. @media (prefers-reduced-motion: reduce) {
  132. transition: none;
  133. }
  134. .w-userbar.is-active & {
  135. opacity: 1;
  136. transform: translateY(0);
  137. transition-delay: 0.3s;
  138. }
  139. }
  140. .w-userbar-nav {
  141. background: transparent;
  142. padding: 0;
  143. margin: 0;
  144. display: block;
  145. .w-action {
  146. background: transparent;
  147. }
  148. }
  149. .w-userbar__item {
  150. margin: 0;
  151. background-color: $color-grey-1;
  152. opacity: 0;
  153. overflow: hidden;
  154. transition-duration: 0.125s;
  155. transition-timing-function: cubic-bezier(0.55, 0, 0.1, 1);
  156. font-family: $font-sans;
  157. font-size: 1rem;
  158. text-decoration: none;
  159. @media (prefers-reduced-motion: reduce) {
  160. transition: none;
  161. // Force disable transitions for all items
  162. transition-delay: 0s;
  163. }
  164. &:first-child {
  165. // Remove once we drop support for Safari 14.
  166. // stylelint-disable-next-line property-disallowed-list
  167. border-top-left-radius: $userbar-radius;
  168. border-start-start-radius: $userbar-radius;
  169. // Remove once we drop support for Safari 14.
  170. // stylelint-disable-next-line property-disallowed-list
  171. border-top-right-radius: $userbar-radius;
  172. border-start-end-radius: $userbar-radius;
  173. }
  174. &:last-child {
  175. // Remove once we drop support for Safari 14.
  176. // stylelint-disable-next-line property-disallowed-list
  177. border-bottom-right-radius: $userbar-radius;
  178. border-end-end-radius: $userbar-radius;
  179. // Remove once we drop support for Safari 14.
  180. // stylelint-disable-next-line property-disallowed-list
  181. border-bottom-left-radius: $userbar-radius;
  182. border-end-start-radius: $userbar-radius;
  183. }
  184. & + & {
  185. border-top: 1px solid $color-black;
  186. }
  187. a,
  188. .w-action {
  189. color: $color-white;
  190. display: block;
  191. text-decoration: none;
  192. transform: none;
  193. transition: none;
  194. margin: 0;
  195. font-size: 0.875rem;
  196. &:hover,
  197. &:focus {
  198. color: $color-white;
  199. background-color: rgba(100, 100, 100, 0.15);
  200. }
  201. &:focus {
  202. outline: $color-focus-outline solid 3px;
  203. }
  204. &-icon {
  205. @include svg-icon(1.1em, middle);
  206. margin-inline-end: 0.5em;
  207. fill: currentColor;
  208. }
  209. }
  210. .w-icon {
  211. position: relative;
  212. &:before {
  213. position: absolute;
  214. top: 50%;
  215. transform: translateY(-50%);
  216. inset-inline-start: 14px;
  217. }
  218. }
  219. a,
  220. button {
  221. font-size: 0.875rem;
  222. text-align: start;
  223. padding: 0.8em;
  224. }
  225. button {
  226. border: 0;
  227. width: 100%;
  228. background-color: transparent;
  229. outline: none;
  230. }
  231. }
  232. //Media for Windows High Contrast
  233. @media (forced-colors: $media-forced-colours) {
  234. .w-userbar-icon {
  235. fill: $system-color-link-text;
  236. }
  237. .w-userbar__item {
  238. border: 1px solid $system-color-button-text;
  239. }
  240. .w-userbar-items::after {
  241. border: $width-arrow solid Canvas;
  242. }
  243. }
  244. // =============================================================================
  245. // Userbar positional classes (tl, tr, bl, br)
  246. // =============================================================================
  247. @each $pos, $attrs in $positions {
  248. $vertical: map.get($attrs, vertical);
  249. $horizontal: map.get($attrs, horizontal);
  250. $arrow: map.get($attrs, arrow);
  251. .w-userbar--#{$pos} {
  252. #{$vertical}: $position;
  253. #{$horizontal}: $position;
  254. .w-userbar-items {
  255. #{$vertical}: 100%;
  256. #{$horizontal}: 0;
  257. padding-#{$vertical}: $width-arrow * 2;
  258. }
  259. .w-userbar-nav .w-userbar__item {
  260. @if $vertical == 'bottom' {
  261. transform: translateY(1em);
  262. } @else {
  263. transform: translateY(-1em);
  264. }
  265. }
  266. .w-userbar-items:after {
  267. #{$vertical}: 2px;
  268. #{$horizontal}: math.div($size-home-button, 2) -
  269. math.div($width-arrow, 2);
  270. border-#{$arrow}-color: $color-grey-1;
  271. @if $vertical == 'bottom' {
  272. transform: translateY($width-arrow);
  273. }
  274. @if $vertical == 'top' {
  275. transform: translateY($width-arrow);
  276. }
  277. }
  278. &.is-active .w-userbar__item {
  279. @for $i from 1 through $max-items {
  280. @if $vertical == 'bottom' {
  281. &:nth-last-child(#{$i}) {
  282. transition-delay: 0.05s * $i;
  283. }
  284. }
  285. @if $vertical == 'top' {
  286. &:nth-child(#{$i}) {
  287. transition-delay: 0.05s * $i;
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. // =============================================================================
  295. // States
  296. // =============================================================================
  297. // Active state for the list items comes last.
  298. .w-userbar.is-active .w-userbar__item {
  299. transform: translateY(0);
  300. opacity: 1;
  301. }