userbar.scss 8.1 KB

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