Loggest thine Stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
5.2 KiB

  1. <script lang="ts">
  2. import { getModalContext } from "../contexts/ModalContext.svelte";
  3. import Icon from "../layout/Icon.svelte";
  4. export let show: boolean = false;
  5. export let verb: string = "Submit";
  6. export let noun: string = "Form";
  7. export let wide: boolean = false;
  8. export let error: string | null = null;
  9. export let closable: boolean = false;
  10. export let disabled: boolean = false;
  11. const {closeModal} = getModalContext();
  12. </script>
  13. {#if show}
  14. <div class="modal-background">
  15. <div class="modal" class:wide>
  16. <div class="header">
  17. <div class="title" class:noclose={!closable}>{verb} {noun}</div>
  18. {#if (closable)}
  19. <div class="x">
  20. <div class="button" on:click={closeModal}>
  21. <Icon name="times" />
  22. </div>
  23. </div>
  24. {/if}
  25. </div>
  26. {#if (error != null)}
  27. <div class="error">{error}</div>
  28. {/if}
  29. <div class="body">
  30. <slot></slot>
  31. </div>
  32. <div class="button-row">
  33. <button disabled={disabled} type="submit">{verb} {noun}</button>
  34. <button disabled={!closable} on:click|preventDefault={closeModal} >Cancel</button>
  35. </div>
  36. </div>
  37. </div>
  38. {/if}
  39. <style lang="scss">
  40. @import "../../css/colors";
  41. div.modal-background {
  42. position: fixed;
  43. top: 0;
  44. left: 0;
  45. width: 100%;
  46. height: 100%;
  47. background: rgba(0,0,0,0.5);
  48. }
  49. div.modal {
  50. position: absolute;
  51. left: 50%;
  52. top: 50%;
  53. width: calc(100vw - 4em);
  54. max-width: 40ch;
  55. max-height: calc(100vh - 4em);
  56. overflow: auto;
  57. transform: translate(-50%,-50%);
  58. border-radius: 0.5em;
  59. background: $color-entry1;
  60. }
  61. div.modal.wide {
  62. max-width: 80ch;
  63. }
  64. div.header {
  65. padding: 1em;
  66. margin-bottom: 0;
  67. padding-bottom: 0;
  68. }
  69. div.error {
  70. margin: 0.5em;
  71. padding: 0.5em;
  72. border: 1px solid rgb(204, 65, 65);
  73. border-radius: 0.2em;
  74. background-color: rgb(133, 39, 39);
  75. color: rgb(211, 141, 141);
  76. animation: fadein 0.5s;
  77. }
  78. div.body {
  79. padding: 1em 0;
  80. margin-top: 0;
  81. padding-top: 0;
  82. display: flex;
  83. flex-direction: row;
  84. @media screen and (max-width: 749px) {
  85. display: block;
  86. }
  87. }
  88. div.title {
  89. color: $color-entry10;
  90. line-height: 1em;
  91. }
  92. div.x {
  93. position: relative;
  94. line-height: 1em;
  95. top: -1em;
  96. text-align: right;
  97. }
  98. div.x div.button {
  99. color: $color-entry7;
  100. display: inline-block;
  101. padding: 0em 0.5ch 0.1em 0.5ch;
  102. line-height: 1em;
  103. user-select: none;
  104. cursor: pointer;
  105. }
  106. div.x div.button:hover {
  107. color: $color-entry10;
  108. }
  109. div.button-row {
  110. display: flex;
  111. flex-direction: row;
  112. border-top: 0.5px solid $color-entry2;
  113. button {
  114. display: inline-block;
  115. padding: 0.25em 1ch;
  116. font-size: 1.25em;
  117. background: none;
  118. border: none;
  119. color: $color-entry7;
  120. border-left : 0.5px solid $color-entry2;
  121. cursor: pointer;
  122. }
  123. button:first-of-type {
  124. margin-left: auto;
  125. }
  126. button:hover {
  127. background-color: $color-entryhalf;
  128. }
  129. button:disabled {
  130. color: $color-entry4;
  131. }
  132. }
  133. div.modal :global(label) {
  134. padding: 1em 0 0.125em 0.25ch;
  135. font-size: 0.9em;
  136. user-select: none;
  137. -webkit-user-select: none;
  138. -moz-user-select: none;
  139. }
  140. div.modal :global(input), div.modal :global(select), div.modal :global(textarea) {
  141. width: calc(100% - 2ch);
  142. margin-bottom: 1em;
  143. margin-top: 0.25em;
  144. background: $color-entryhalf;
  145. color: $color-entry8;
  146. border: none;
  147. outline: none;
  148. resize: vertical;
  149. padding: 0.5em 1ch;
  150. }
  151. div.modal :global(select) {
  152. padding-left: 0.5ch;
  153. padding: 0.45em 1ch;
  154. width: 100%;
  155. }
  156. div.modal :global(select option), div.modal :global(select optgroup) {
  157. -webkit-appearance: none;
  158. -moz-appearance: none;
  159. appearance: none;
  160. padding: 0.5em 0;
  161. }
  162. div.modal :global(input)::placeholder {
  163. opacity: 0.5;
  164. }
  165. div.modal :global(select:disabled) {
  166. background: $color-entryhalf;
  167. color: $color-entry4;
  168. }
  169. div.modal :global(input:disabled) {
  170. background: $color-entryhalf;
  171. color: $color-entry4;
  172. }
  173. div.modal :global(textarea) {
  174. min-height: 3.5em;
  175. height: 3.5em;
  176. font-family: inherit;
  177. }
  178. div.modal :global(textarea:disabled) {
  179. background: #444;
  180. color: #aaa;
  181. }
  182. div.modal :global(input.nolast) {
  183. margin-bottom: 0.5em;
  184. }
  185. div.modal :global(input[type="checkbox"]) {
  186. width: initial;
  187. display: inline-block;
  188. }
  189. div.modal :global(input[type="checkbox"] + label) {
  190. width: initial;
  191. display: inline-block;
  192. padding: 0;
  193. margin: 0;
  194. }
  195. div.modal :global(input:focus), div.modal :global(select:focus), div.modal :global(textarea:focus) {
  196. background: $color-entry0;
  197. color: $color-entry10;
  198. border: none;
  199. outline: none;
  200. }
  201. div.modal :global(p) {
  202. margin: 0.25em 1ch 1em 1ch;
  203. font-size: 0.9em;
  204. }
  205. div.modal :global(input::-webkit-outer-spin-button),
  206. div.modal :global(input::-webkit-inner-spin-button) {
  207. -webkit-appearance: none;
  208. margin: 0;
  209. }
  210. div.modal :global(input[type=number]) {
  211. -moz-appearance: textfield;
  212. }
  213. @keyframes fadein {
  214. from { opacity: 0; }
  215. to { opacity: 1; }
  216. }
  217. </style>