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.
 
 

99 lines
1.8 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. width: '100%',
  26. height: '100%',
  27. display: 'flex',
  28. alignItems: 'center',
  29. maxWidth: 'calc(var(--width-base, 360px) * 2)',
  30. '@media (min-width: 1080px)': {
  31. maxWidth: 'calc(var(--width-base, 360px) * 3)',
  32. },
  33. })
  34. const BrandContainer = styled('div')({
  35. width: '6rem',
  36. '@media (min-width: 720px)': {
  37. width: '8rem',
  38. },
  39. })
  40. const SearchContainer = styled('form')({
  41. flex: 'auto',
  42. padding: '0 1rem',
  43. boxSizing: 'border-box',
  44. })
  45. const UserContainer = styled('div')({
  46. textAlign: 'right',
  47. '@media (min-width: 720px)': {
  48. minWidth: '8rem',
  49. },
  50. })
  51. type Props = {
  52. query?: string,
  53. onSearch?: React.FormEventHandler,
  54. searchLabel?: string,
  55. searchName?: string,
  56. searchHint?: string,
  57. }
  58. const TopBar: React.FC<Props> = ({
  59. query,
  60. onSearch,
  61. searchLabel = 'Search',
  62. searchName = 'q',
  63. searchHint = 'e.g. keywords, names…',
  64. }) => {
  65. return (
  66. <Base>
  67. <Container>
  68. <BrandContainer>
  69. Brand
  70. </BrandContainer>
  71. <SearchContainer
  72. onSubmit={onSearch}
  73. >
  74. <T.TextInput
  75. name={searchName}
  76. label={searchLabel}
  77. hint={searchHint}
  78. defaultValue={query}
  79. border
  80. alternate
  81. />
  82. </SearchContainer>
  83. <UserContainer>
  84. User
  85. </UserContainer>
  86. </Container>
  87. </Base>
  88. )
  89. }
  90. export default TopBar