Template for starting apps, powered by Next.js
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.
 
 

96 lines
1.7 KiB

  1. import * as React from 'react'
  2. import styled from 'styled-components'
  3. import * as T from '@tesseract-design/react-common'
  4. const Base = styled('div')({
  5. '--width-base': '360px',
  6. '--height-topbar': '4rem',
  7. position: 'fixed',
  8. top: 0,
  9. left: 0,
  10. width: '100%',
  11. height: 'var(--height-topbar, 4rem)',
  12. backgroundColor: 'var(--color-bg, white)',
  13. zIndex: 1,
  14. '@media (prefers-color-scheme: dark)': {
  15. backgroundColor: 'var(--color-bg, black)',
  16. },
  17. '~ *': {
  18. paddingTop: 'var(--height-topbar, 4rem)',
  19. },
  20. })
  21. const Container = styled('div')({
  22. padding: '0 1rem',
  23. boxSizing: 'border-box',
  24. margin: '0 auto',
  25. maxWidth: 'calc(var(--width-base, 360px) * 2)',
  26. width: '100%',
  27. height: '100%',
  28. display: 'flex',
  29. alignItems: 'center',
  30. })
  31. const BrandContainer = styled('div')({
  32. width: '6rem',
  33. '@media (min-width: 720px)': {
  34. width: '8rem',
  35. },
  36. })
  37. const SearchContainer = styled('form')({
  38. flex: 'auto',
  39. padding: '0 1rem',
  40. boxSizing: 'border-box',
  41. })
  42. const UserContainer = styled('div')({
  43. textAlign: 'right',
  44. '@media (min-width: 720px)': {
  45. minWidth: '8rem',
  46. },
  47. })
  48. type Props = {
  49. query?: string,
  50. onSearch?: React.FormEventHandler,
  51. searchLabel?: string,
  52. searchName?: string,
  53. searchHint?: string,
  54. }
  55. const TopBar: React.FC<Props> = ({
  56. query,
  57. onSearch,
  58. searchLabel = 'Search',
  59. searchName = 'q',
  60. searchHint = 'e.g. keywords, names…',
  61. }) => {
  62. return (
  63. <Base>
  64. <Container>
  65. <BrandContainer>
  66. Brand
  67. </BrandContainer>
  68. <SearchContainer
  69. onSubmit={onSearch}
  70. >
  71. <T.TextInput
  72. name={searchName}
  73. label={searchLabel}
  74. hint={searchHint}
  75. defaultValue={query}
  76. border
  77. alternate
  78. />
  79. </SearchContainer>
  80. <UserContainer>
  81. User
  82. </UserContainer>
  83. </Container>
  84. </Base>
  85. )
  86. }
  87. export default TopBar