mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-10 16:14:19 +02:00
feat: Search box
This commit is contained in:
4
contents/_includes/patterns/search-box.njk
Normal file
4
contents/_includes/patterns/search-box.njk
Normal file
@@ -0,0 +1,4 @@
|
||||
<div class="search-box">
|
||||
<input type="text" class="search-box__input" />
|
||||
{% circle "md" %}
|
||||
</div>
|
@@ -94,6 +94,7 @@ eleventyExcludeFromCollections: true
|
||||
{% pattern "Input addon" %}{% include "patterns/input-addon.njk" %}{% endpattern %}
|
||||
{% pattern "Radio switch" %}{% include "patterns/radio-switch.njk" %}{% endpattern %}
|
||||
{% pattern "Rating" %}{% include "patterns/rating.njk" %}{% endpattern %}
|
||||
{% pattern "Search box" %}{% include "patterns/search-box.njk" %}{% endpattern %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
40
contents/search-box.md
Normal file
40
contents/search-box.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Search box
|
||||
description: Create a search box with CSS flexbox
|
||||
keywords: css flexbox, css search box
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="search-box">
|
||||
<!-- Text input -->
|
||||
<input type="text" class="search-box__input" />
|
||||
|
||||
<!-- Search icon sticks to the left or right -->
|
||||
...
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.search-box {
|
||||
display: flex;
|
||||
|
||||
/* If you want to place the icon before the text input */
|
||||
flex-direction: row-reverse;
|
||||
|
||||
/* Border */
|
||||
border: 1px solid #d1d5db;
|
||||
}
|
||||
|
||||
.search-box__input {
|
||||
border-color: transparent;
|
||||
/* Take available width */
|
||||
flex: 1;
|
||||
}
|
||||
```
|
||||
|
||||
{% demo %}{% include "patterns/search-box.njk" %}{% enddemo %}
|
@@ -1,107 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import Head from 'next/head';
|
||||
|
||||
import { Pattern } from '../../constants/Pattern';
|
||||
import { PatternLayout } from '../../layouts/PatternLayout';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
import Circle from '../../placeholders/Circle';
|
||||
|
||||
const Details: React.FC<{}> = () => {
|
||||
return (
|
||||
<PatternLayout pattern={Pattern.SearchBox}>
|
||||
<Head>
|
||||
<meta name="description" content="Create a search box with CSS flexbox" />
|
||||
<meta name="og:description" content="Create a search box with CSS flexbox" />
|
||||
<meta name="twitter:description" content="Create a search box with CSS flexbox" />
|
||||
<meta name="keywords" content="css flexbox, css search box" />
|
||||
</Head>
|
||||
<BrowserFrame
|
||||
html={`
|
||||
<div class="container">
|
||||
<!-- Text input -->
|
||||
<input type="text" class="container__input" />
|
||||
|
||||
<!-- Search icon sticks to the left or right -->
|
||||
...
|
||||
</div>
|
||||
`}
|
||||
css={`
|
||||
.container {
|
||||
display: flex;
|
||||
|
||||
/* If you want to place the icon before the text input */
|
||||
flex-direction: row-reverse;
|
||||
|
||||
/* Border */
|
||||
border: 1px solid #d1d5db;
|
||||
}
|
||||
|
||||
.container__input {
|
||||
border-color: transparent;
|
||||
/* Take available width */
|
||||
flex: 1;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div style={{ width: '256px' }}>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '2px',
|
||||
display: 'flex',
|
||||
marginBottom: '16px',
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search"
|
||||
style={{
|
||||
borderColor: 'transparent',
|
||||
flex: 1,
|
||||
padding: '4px',
|
||||
}}
|
||||
/>
|
||||
<div style={{ padding: '8px' }}>
|
||||
<Circle />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '2px',
|
||||
display: 'flex',
|
||||
flexDirection: 'row-reverse',
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search"
|
||||
style={{
|
||||
borderColor: 'transparent',
|
||||
flex: 1,
|
||||
padding: '4px',
|
||||
}}
|
||||
/>
|
||||
<div style={{ padding: '8px' }}>
|
||||
<Circle />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
</PatternLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
@@ -1,37 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import Circle from '../../placeholders/Circle';
|
||||
import Frame from '../../placeholders/Frame';
|
||||
|
||||
const Cover: React.FC<{}> = () => {
|
||||
return (
|
||||
<Frame>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '4px',
|
||||
display: 'flex',
|
||||
justifyContent: 'flex-end',
|
||||
padding: '4px',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<Circle />
|
||||
</div>
|
||||
</div>
|
||||
</Frame>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cover;
|
@@ -1,55 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import { random } from '../utils/random';
|
||||
|
||||
interface BlockProps {
|
||||
backgroundColor?: string;
|
||||
blockHeight?: number;
|
||||
justify?: string;
|
||||
numberOfBlocks?: number;
|
||||
}
|
||||
|
||||
const Block: React.FC<BlockProps> = ({
|
||||
backgroundColor = '#d1d5db',
|
||||
blockHeight = 4,
|
||||
justify = 'start',
|
||||
numberOfBlocks = 1,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
justifyContent: justify,
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
{Array(numberOfBlocks)
|
||||
.fill(0)
|
||||
.map((_, i) => {
|
||||
const s = random(1, 5);
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
style={{
|
||||
marginBottom: '8px',
|
||||
marginRight: '8px',
|
||||
width: `${s * 10}%`,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
backgroundColor,
|
||||
borderRadius: '9999px',
|
||||
height: `${blockHeight}px`,
|
||||
width: '100%',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Block;
|
@@ -1,19 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
const Frame: React.FC<{}> = ({ children }) => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '2px',
|
||||
boxShadow: 'rgba(0, 0, 0, 0.2) 0px 16px 24px -4px, rgba(0, 0, 0, 0.05) 0px 8px 8px -4px',
|
||||
height: '100px',
|
||||
width: '100px',
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Frame;
|
@@ -62,6 +62,7 @@
|
||||
@import './patterns/rating';
|
||||
@import './patterns/resizable-element';
|
||||
@import './patterns/ribbon';
|
||||
@import './patterns/search-box';
|
||||
@import './patterns/separator';
|
||||
@import './patterns/stacked-cards';
|
||||
@import './patterns/stamp-border';
|
||||
|
23
styles/patterns/_search-box.scss
Normal file
23
styles/patterns/_search-box.scss
Normal file
@@ -0,0 +1,23 @@
|
||||
.search-box {
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
/* Demo */
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.search-box__input {
|
||||
border-color: transparent;
|
||||
|
||||
/* Take available width */
|
||||
flex: 1;
|
||||
|
||||
height: 2rem;
|
||||
margin-right: 0.25rem;
|
||||
|
||||
/* Demo */
|
||||
width: 6rem;
|
||||
}
|
Reference in New Issue
Block a user