UNPKG

3.85 kBJavaScriptView Raw
1/** Style for visually hidden but accessible for screenReaders */
2export const WUPcssHidden = `
3position: absolute;
4height:1px; width:1px;
5overflow:hidden;
6clip:rect(1px,1px,1px,1px);
7min-width:initial;
8padding:0;`;
9/** Style for icons; vars --ctrl-icon, --ctrl-icon-size, --ctrl-icon-img to customize styling */
10export const WUPcssIcon = `
11display: inline-block;
12width: var(--ctrl-icon-size);
13min-height: var(--ctrl-icon-size);
14box-sizing: content-box;
15margin: 0;
16padding: 5px;
17flex: 0 0 auto;
18align-self: stretch;
19border: none;
20box-shadow: none;
21background: var(--ctrl-icon);
22-webkit-mask-size: var(--ctrl-icon-size);
23mask-size: var(--ctrl-icon-size);
24-webkit-mask-repeat: no-repeat;
25mask-repeat: no-repeat;
26-webkit-mask-position: center;
27mask-position: center;
28-webkit-mask-image: var(--ctrl-icon-img);
29mask-image: var(--ctrl-icon-img);`;
30/** Style for small-scroll; vars --scroll, --scroll-hover to customize styling
31 * @tutorial Troubleshooting
32 * * cursor:pointer; doesn't work - this Chromium issue https://stackoverflow.com/questions/64402424/why-does-the-css-cursor-property-not-work-for-the-styled-scrollbar */
33export function WUPcssScrollSmall(tag) {
34 return `
35${tag}::-webkit-scrollbar {
36 width: 10px; height: 10px;
37 cursor: pointer;
38}
39${tag}::-webkit-scrollbar-corner {
40 background: none;
41 cursor: pointer;
42}
43${tag}::-webkit-scrollbar-thumb {
44 border: 3px solid rgba(0,0,0,0);
45 background-clip: padding-box;
46 background-color: var(--scroll, rgba(0,0,0,0.2));
47 border-radius: 999px;
48 cursor: pointer;
49}
50${tag}::-webkit-scrollbar-track-piece:vertical:start,
51${tag}::-webkit-scrollbar-track-piece:vertical:end,
52${tag}::-webkit-scrollbar-track-piece:horizontal:start,
53${tag}::-webkit-scrollbar-track-piece:horizontal:end {
54 margin: 0;
55 cursor: pointer;
56}
57@media (hover) {
58 ${tag}::-webkit-scrollbar-thumb:hover {
59 background-color: var(--scroll-hover, rgba(0,0,0,0.5));
60 cursor: pointer;
61 }
62}`;
63}
64/** Returns default style for primary/submit button */
65export function WUPcssButton(tag) {
66 return `
67${tag} {
68 box-shadow: none;
69 border: 1px solid var(--base-btn-bg);
70 border-radius: var(--border-radius);
71 box-sizing: border-box;
72 padding: 0.5em;
73 margin: 1em 0;
74 min-width: 10em;
75 cursor: pointer;
76 font: inherit;
77 font-weight: bold;
78 background: var(--base-btn-bg);
79 color: var(--base-btn-text);
80 outline: none;
81}
82${tag}:focus {
83 border-color: var(--base-btn-focus);
84}
85@media (hover: hover) and (pointer: fine) {
86 ${tag}:hover {
87 box-shadow: inset 0 0 0 99999px rgba(0,0,0,0.2);
88 }
89}
90${tag}[disabled] {
91 opacity: 0.3;
92 cursor: not-allowed;
93 -webkit-user-select: none;
94 user-select: none;
95}
96${tag}[aria-busy] {
97 cursor: wait;
98}`;
99}
100/** Returns default style for popup menu */
101export function WUPcssMenu(tag) {
102 return `
103${tag} {
104 padding: 0;
105 overflow: hidden;
106}
107${tag} ul {
108 margin: 0;
109 padding: 0;
110 list-style-type: none;
111 cursor: pointer;
112 overflow: auto;
113 max-height: 300px;
114}
115${WUPcssScrollSmall(`${tag} ul`)}
116${tag} li {
117 padding: 1em;
118 border-radius: var(--border-radius);
119}
120@media (hover: hover) and (pointer: fine) {
121 ${tag} li:hover {
122 box-shadow: inset 0 0 3px 0 var(--base-focus);
123 }
124}
125${tag} li[aria-selected="true"] {
126 color: var(--ctrl-selected);
127 display: flex;
128}
129${tag} li[aria-selected="true"]:after {
130 content: "";
131 --ctrl-icon-img: var(--wup-icon-check);
132 ${WUPcssIcon}
133 background: var(--ctrl-selected);
134 margin-left: auto;
135 padding: 0;
136}
137${tag} li[focused] {
138 box-shadow: inset 0 0 4px 0 var(--base-focus);
139}`;
140}
141let refStyle;
142/** Use this function to prepend css-style via JS into document.head */
143export function useBuiltinStyle(cssString) {
144 if (!refStyle) {
145 refStyle = document.createElement("style");
146 document.head.prepend(refStyle);
147 }
148 refStyle.append(cssString);
149 return refStyle;
150}