Website for showcasing all features of Tesseract Web.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

304 wiersze
5.4 KiB

  1. import { css } from '@tesseract-design/css-utils';
  2. export enum ButtonSize {
  3. SMALL = 'small',
  4. MEDIUM = 'medium',
  5. LARGE = 'large',
  6. }
  7. export enum ButtonVariant {
  8. OUTLINE = 'outline',
  9. FILLED = 'filled',
  10. }
  11. export enum ButtonStyle {
  12. DEFAULT = 'default',
  13. }
  14. export type ButtonBaseArgs = {
  15. size: ButtonSize,
  16. block: boolean,
  17. variant: ButtonVariant,
  18. border: boolean,
  19. disabled: boolean,
  20. style: ButtonStyle,
  21. compact: boolean,
  22. menuItem: boolean,
  23. }
  24. const MIN_HEIGHTS: Record<ButtonSize, string> = {
  25. [ButtonSize.SMALL]: '2.5rem',
  26. [ButtonSize.MEDIUM]: '3rem',
  27. [ButtonSize.LARGE]: '4rem',
  28. };
  29. export const Button = ({
  30. size,
  31. block,
  32. variant,
  33. disabled,
  34. compact,
  35. }: ButtonBaseArgs): string => css.cx(
  36. css`
  37. box-sizing: border-box;
  38. vertical-align: middle;
  39. appearance: none;
  40. font: inherit;
  41. font-family: var(--font-family-base, sans-serif);
  42. text-transform: uppercase;
  43. font-weight: bolder;
  44. border-radius: 0.25rem;
  45. justify-content: center;
  46. align-items: center;
  47. position: relative;
  48. border: 0;
  49. user-select: none;
  50. text-decoration: none;
  51. white-space: nowrap;
  52. line-height: 1;
  53. & > :first-child::before {
  54. box-shadow: 0 0 0 0 var(--color-accent, blue);
  55. transition-property: box-shadow;
  56. transition-duration: 150ms;
  57. transition-timing-function: linear;
  58. }
  59. &:disabled {
  60. opacity: 0.5;
  61. cursor: not-allowed;
  62. }
  63. &::-moz-focus-inner {
  64. outline: 0;
  65. border: 0;
  66. }
  67. &:focus > :first-child::before {
  68. box-shadow: 0 0 0 0.375rem var(--color-accent, blue);
  69. }
  70. &:disabled > :first-child::before {
  71. box-shadow: 0 0 0 0 var(--color-accent, blue) !important;
  72. }
  73. `,
  74. css.dynamic({
  75. 'min-height': MIN_HEIGHTS[size],
  76. }),
  77. css.if (disabled) (
  78. css`
  79. --color-accent: var(--color-primary, blue);
  80. opacity: 0.5;
  81. cursor: not-allowed;
  82. `
  83. ).else (
  84. css`
  85. cursor: pointer;
  86. &:hover {
  87. --color-accent: var(--color-hover, blue);
  88. outline: 0;
  89. }
  90. &:focus {
  91. --color-accent: var(--color-hover, blue);
  92. outline: 0;
  93. }
  94. &:active {
  95. --color-accent: var(--color-active, red);
  96. outline: 0;
  97. }
  98. &:hover > :first-child::before {
  99. box-shadow: 0 0 0 0.375rem var(--color-accent, blue);
  100. }
  101. `
  102. ),
  103. css.if (block) (
  104. css`
  105. width: 100%;
  106. display: flex;
  107. `
  108. ).else (
  109. css`
  110. display: inline-flex;
  111. `
  112. ),
  113. css.if (compact) (
  114. css`
  115. font-stretch: condensed;
  116. padding: 0 0.5rem;
  117. `
  118. ).else(
  119. css`
  120. padding: 0 1rem;
  121. `
  122. ),
  123. css.if (variant === ButtonVariant.FILLED) (
  124. css`
  125. background-color: var(--color-accent, blue);
  126. color: var(--color-bg, white) !important;
  127. `
  128. ),
  129. css.if (variant === ButtonVariant.OUTLINE) (
  130. css`
  131. background-color: var(--color-bg, white);
  132. color: var(--color-accent, blue);
  133. `
  134. ),
  135. );
  136. export const Border = ({
  137. border
  138. }: ButtonBaseArgs): string => css.cx(
  139. css.if (border) (
  140. css`
  141. border-color: var(--color-accent, blue);
  142. box-sizing: border-box;
  143. display: inline-block;
  144. border-width: 0.125rem;
  145. border-style: solid;
  146. position: absolute;
  147. top: 0;
  148. left: 0;
  149. width: 100%;
  150. height: 100%;
  151. border-radius: inherit;
  152. pointer-events: none;
  153. &::before {
  154. position: absolute;
  155. top: 0;
  156. left: 0;
  157. width: 100%;
  158. height: 100%;
  159. content: '';
  160. border-radius: 0.125rem;
  161. opacity: 0.5;
  162. pointer-events: none;
  163. }
  164. `
  165. ),
  166. );
  167. export const Label = ({
  168. compact,
  169. menuItem,
  170. }: ButtonBaseArgs): string => css.cx(
  171. css`
  172. display: block;
  173. flex-grow: 1;
  174. flex-basis: 0;
  175. min-width: 0;
  176. `,
  177. css.if (compact || menuItem) (
  178. css`
  179. text-align: left;
  180. `
  181. ).else (
  182. css`
  183. text-align: center;
  184. `
  185. ),
  186. css.if (compact) (
  187. css`
  188. & ~ :last-child {
  189. margin-right: -0.5rem;
  190. }
  191. `
  192. ).else (
  193. css`
  194. & ~ :last-child {
  195. margin-right: -1rem;
  196. }
  197. `
  198. ),
  199. );
  200. export const BadgeContainer = ({
  201. size,
  202. }: ButtonBaseArgs): string => css.cx(
  203. css`
  204. width: 2rem;
  205. text-align: center;
  206. flex-shrink: 0;
  207. & + * {
  208. margin-left: -0.5rem;
  209. }
  210. `,
  211. css.nest('&:last-child')(
  212. css.dynamic({
  213. width: MIN_HEIGHTS[size],
  214. })
  215. ),
  216. );
  217. export const OverflowText = (): string => css.cx(
  218. css`
  219. width: 100%;
  220. display: block;
  221. overflow: hidden;
  222. text-overflow: ellipsis;
  223. height: 1.1em;
  224. line-height: 1;
  225. `,
  226. );
  227. export const IndicatorWrapper = ({
  228. size
  229. }: ButtonBaseArgs): string => css.cx(
  230. css`
  231. flex-shrink: 0;
  232. box-sizing: border-box;
  233. display: grid;
  234. place-content: center;
  235. padding: 0 1rem;
  236. z-index: 1;
  237. pointer-events: none;
  238. line-height: 1;
  239. user-select: none;
  240. `,
  241. css.dynamic({
  242. width: `calc(${MIN_HEIGHTS[size]} * 0.75)`,
  243. height: MIN_HEIGHTS[size],
  244. }),
  245. );
  246. export const Indicator = () => css.cx(
  247. css`
  248. width: 1.5em;
  249. height: 1.5em;
  250. fill: none;
  251. stroke: currentColor;
  252. stroke-width: 2;
  253. stroke-linecap: round;
  254. stroke-linejoin: round;
  255. `,
  256. );
  257. export const MainText = () => css.cx(
  258. css`
  259. width: 100%;
  260. `,
  261. );
  262. export const Subtext = () => css.cx(
  263. css`
  264. display: block;
  265. height: 1.1em;
  266. line-height: 1.1;
  267. width: 100%;
  268. font-size: 0.875em;
  269. text-transform: none;
  270. font-weight: var(--font-weight-base, normal);
  271. `,
  272. );