1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-07 14:46:38 +02:00

Add CSS code for input patterns

This commit is contained in:
Phuoc Nguyen
2021-03-31 20:55:44 +07:00
parent b5ef930f42
commit 14b0781512
11 changed files with 300 additions and 287 deletions

View File

@@ -22,13 +22,7 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<button style=" <button class="button">
/* Center the content */
align-items: center;
display: flex;
flex-direction: row;
justify-content: center;
">
<!-- Icon --> <!-- Icon -->
... ...
@@ -36,7 +30,15 @@ html={`
... ...
</div> </div>
`} `}
css={``} css={`
.button {
/* Center the content */
align-items: center;
display: flex;
flex-direction: row;
justify-content: center;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -26,7 +26,19 @@ const Details: React.FC<{}> = () => {
</div> </div>
<BrowserFrame <BrowserFrame
html={` html={`
<div style=" <div class="chip">
<!-- Content -->
<div class="chip__content">
...
</div>
<!-- The close button -->
<!-- See https://csslayout.io/patterns/close-button -->
...
</div>
`}
css={`
.chip {
/* Center the content */ /* Center the content */
align-items: center; align-items: center;
display: inline-flex; display: inline-flex;
@@ -40,18 +52,12 @@ html={`
/* Spacing */ /* Spacing */
padding: 4px 8px; padding: 4px 8px;
"> }
<!-- Content -->
<div style="margin-right: 4px;">
...
</div>
<!-- The close button --> .chip__content {
<!-- See https://csslayout.io/patterns/close-button --> margin-right: 4px;
... }
</div>
`} `}
css={``}
> >
<div <div
style={{ style={{

View File

@@ -71,51 +71,56 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<label style=" <label class="label">
/* Center the content horizontally */
align-items: center;
display: inline-flex;
/* Cursor */
cursor: pointer;
">
<!-- The real checkbox --> <!-- The real checkbox -->
<input <input type="checkbox" class="label__input" />
type="checkbox"
style="
/* Hide it */
display: none;
"
/>
<!-- The fake square --> <!-- The fake square -->
<div style=" <div class="label__square">
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 4px;
/* Spacing */
margin-right: 8px;
padding: 4px;
">
<!-- The inner square --> <!-- The inner square -->
<div style=" <div class="label__checkbox label__square--selected"></div>
border-radius: 4px;
height: 16px;
width: 16px;
/* For selected checkbox */
background-color: #00449E;
/* For not selected checkbox */
background-color: transparent;
" />
</div> </div>
<!-- The text --> <!-- The text -->
... ...
</div> </div>
`} `}
css={``} css={`
.label {
/* Center the content horizontally */
align-items: center;
display: inline-flex;
/* Cursor */
cursor: pointer;
}
.label__input {
/* Hide it */
display: none;
}
.label__square {
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 4px;
/* Spacing */
margin-right: 8px;
padding: 4px;
}
.label__checkbox {
background-color: transparent;
border-radius: 4px;
height: 16px;
width: 16px;
}
.label__checkbox--selected {
/* For selected checkbox */
background-color: #00449E;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -72,53 +72,60 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<label style=" <label class="label">
/* Center the content horizontally */
align-items: center;
display: inline-flex;
/* Cursor */
cursor: pointer;
">
<!-- The real radio --> <!-- The real radio -->
<input <input type="radio" class="label__input" />
type="radio"
style="
/* Hide it */
display: none;
"
/>
<!-- The fake circle --> <!-- The fake circle -->
<div style=" <div class="label__circle">
/* Rounded border */
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 9999px;
/* Spacing */
margin-right: 8px;
padding: 4px;
">
<!-- The inner circle --> <!-- The inner circle -->
<div style=" <div class="label__radio label__radio--selected"></div>
/* Rounded border */
border-radius: 9999px;
height: 16px;
width: 16px;
/* For selected radio */
background-color: #00449E;
/* For not selected radio */
background-color: transparent;
" />
</div> </div>
<!-- The text --> <!-- The text -->
... ...
</div> </div>
`} `}
css={``} css={`
.label {
/* Center the content horizontally */
align-items: center;
display: inline-flex;
/* Cursor */
cursor: pointer;
}
.label__input {
/* Hide it */
display: none;
}
.label__circle {
/* Rounded border */
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 9999px;
/* Spacing */
margin-right: 8px;
padding: 4px;
}
.label__radio {
/* Rounded border */
border-radius: 9999px;
height: 16px;
width: 16px;
/* For not selected radio */
background-color: transparent;
}
.label__radio--selected {
/* For selected radio */
background-color: #00449E;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -25,12 +25,30 @@ const Details: React.FC<{}> = () => {
</div> </div>
<BrowserFrame <BrowserFrame
html={` html={`
<style> <div class="container">
.p-floating-container { <!-- The input -->
<input placeholder="Placeholder" class="container__input" />
<!-- The label -->
<label class="container__label">Placeholder</label>
</div>
`}
css={`
.container {
position: relative; position: relative;
} }
.p-floating-container label { /*
Show the label at desired position when the
placeholder of input isn't shown
*/
.container__input:not(:placeholder-shown) + .container__label {
background: #FFF;
transform: translate(0, -50%);
opacity: 1;
}
.container__label {
/* Position the label */ /* Position the label */
left: 8px; left: 8px;
position: absolute; position: absolute;
@@ -38,26 +56,9 @@ html={`
/* Hide it by default */ /* Hide it by default */
opacity: 0; opacity: 0;
transition: 'all 200ms', transition: all 200ms;
} }
/* Show the label at desired position when the placeholder of input isn't shown */
.p-floating-container input:not(:placeholder-shown) + label {
background: #FFF;
transform: translate(0, -50%);
opacity: 1;
}
</style>
<div class="p-floating-container">
<!-- The input -->
<input placeholder="Placeholder" />
<!-- The label -->
<label>Placeholder</label>
</div>
`} `}
css={``}
> >
<div <div
style={{ style={{

View File

@@ -22,88 +22,63 @@ const Details: React.FC<{}> = () => {
<BrowserFrame <BrowserFrame
html={` html={`
<!-- Add-on prepended --> <!-- Add-on prepended -->
<div style=" <div class="container">
display: flex;
/* Take full size */
width: 100%;
">
<!-- Add-on --> <!-- Add-on -->
<div style=" <div class="container__addon">
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
">
... ...
</div> </div>
<!-- Input --> <!-- Input -->
<input type="text" style=" <input type="text" class="container__input" />
/* Take the remaining width */
flex: 1;
" />
</div> </div>
<!-- Add-on appended --> <!-- Add-on appended -->
<div style=" <div class="container">
display: flex;
/* Take full size */
width: 100%;
">
<!-- Input --> <!-- Input -->
<input type="text" style=" <input type="text" class="container__input" />
/* Take the remaining width */
flex: 1;
" />
<!-- Add-on --> <!-- Add-on -->
<div style=" <div class="container__addon">
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
">
... ...
</div> </div>
</div> </div>
<!-- Appended and prepended add-ons --> <!-- Appended and prepended add-ons -->
<div style=" <div class="container">
display: flex;
/* Take full size */
width: 100%;
">
<!-- Add-on --> <!-- Add-on -->
<div style=" <div class="container__addon">
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
">
... ...
</div> </div>
<!-- Input --> <!-- Input -->
<input type="text" style=" <input type="text" class="container__input" />
/* Take the remaining width */
flex: 1;
" />
<!-- Add-on --> <!-- Add-on -->
<div style=" <div class="container__addon">
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
">
... ...
</div> </div>
</div> </div>
`} `}
css={``} css={`
.container {
display: flex;
/* Take full size */
width: 100%;
}
.container__input {
/* Take the remaining width */
flex: 1;
}
.container__addon {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -58,51 +58,14 @@ const Details: React.FC<{}> = () => {
<BrowserFrame <BrowserFrame
html={` html={`
<style> <style>
.p-radio-button-group label {
border-right: 1px solid rgba(0, 0, 0, 0.3);
}
/* Remove the right border from the last label */
.p-radio-button-group label:last-child {
border-right-color: transparent;
}
</style> </style>
<div <div class="container">
class="p-radio-button-group"
style="
display: flex;
/* Border */
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 4px;
height: 32px;
"
>
<!-- Each radio item --> <!-- Each radio item -->
<label style=" <label class="container__label">
/* Center the content */
align-items: center;
display: inline-flex;
padding: 8px;
/* For selected radio */
background-color: #00449E;
color: #FFF;
/* For not selected radio */
background-color: transparent;
color: #CCC;
">
<!-- The radio input --> <!-- The radio input -->
<input <input type="radio" class="container__input" />
type="radio"
style="
/* Hide it */
display: none;
"
/>
<!-- The text --> <!-- The text -->
... ...
@@ -112,7 +75,45 @@ html={`
... ...
</div> </div>
`} `}
css={``} css={`
.container {
display: flex;
/* Border */
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 4px;
height: 32px;
}
.container__label {
/* Center the content */
align-items: center;
display: inline-flex;
border-right: 1px solid rgba(0, 0, 0, 0.3);
padding: 8px;
/* For not selected radio */
background-color: transparent;
color: #CCC;
}
.container__label:last-child {
/* Remove the right border from the last label */
border-right-color: transparent;
}
.container__label--selected {
/* For selected radio */
background-color: #00449E;
color: #FFF;
}
.container__input {
/* Hide it */
display: none;
}
`}
> >
<div <div
style={{ style={{

View File

@@ -26,23 +26,10 @@ const Details: React.FC<{}> = () => {
<BrowserFrame <BrowserFrame
html={` html={`
<!-- Container --> <!-- Container -->
<div style=" <div class="container">
background-color: rgba(0, 0, 0, .1);
border-radius: 9999px;
display: inline-flex;
padding: 4px;
">
<!-- Radio container --> <!-- Radio container -->
<label style=" <label class="container__label container__label--selected">
border-radius: 9999px; <input type="radio" class="container__input" />
cursor: pointer;
padding: 4px 8px;
/* For selected radio only */
background-color: #357edd;
color: #fff;
">
<input type="radio" style="display: none" />
<!-- Text --> <!-- Text -->
... ...
@@ -52,7 +39,30 @@ html={`
... ...
</div> </div>
`} `}
css={``} css={`
.container {
background-color: rgba(0, 0, 0, .1);
border-radius: 9999px;
display: inline-flex;
padding: 4px;
}
.container__label {
border-radius: 9999px;
cursor: pointer;
padding: 4px 8px;
}
.container__label--selected {
/* For selected radio only */
background-color: #357edd;
color: #fff;
}
.container__input {
display: none
}
`}
> >
<div <div
style={{ style={{

View File

@@ -21,8 +21,16 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<style> <div class="rating">
.p-rating { <button class="rating__star">☆</button>
<button class="rating__star">☆</button>
<button class="rating__star">☆</button>
<button class="rating__star">☆</button>
<button class="rating__star">★</button>
</div>
`}
css={`
.rating {
/* Center the content */ /* Center the content */
align-items: center; align-items: center;
display: flex; display: flex;
@@ -33,8 +41,8 @@ html={`
font-size: 32px; font-size: 32px;
} }
.p-rating .p-rating-star:hover, .rating__star:hover,
.p-rating .p-rating-star:hover ~ .p-rating-star { .rating__star:hover ~ .rating__star {
color: transparent; color: transparent;
} }
@@ -42,15 +50,15 @@ html={`
Make all previous stars selected when hover on a star Make all previous stars selected when hover on a star
Note that we use \`flex-direction: row-reverse\` on the container Note that we use \`flex-direction: row-reverse\` on the container
*/ */
.p-rating .p-rating-star:hover:before, .rating__star:hover:before,
.p-rating .p-rating-star:hover ~ .p-rating-star:before { .rating__star:hover ~ .rating__star:before {
color: #00449e; color: #00449e;
content: '\\2605'; content: '\\2605';
left: 0; left: 0;
position: absolute; position: absolute;
} }
.p-rating-star { .rating__star {
/* Reset styles for button */ /* Reset styles for button */
background-color: transparent; background-color: transparent;
border: transparent; border: transparent;
@@ -60,17 +68,7 @@ Note that we use \`flex-direction: row-reverse\` on the container
/* Used to position the hover state */ /* Used to position the hover state */
position: relative; position: relative;
} }
</style>
<div class="p-rating">
<button class="p-rating-star">☆</button>
<button class="p-rating-star">☆</button>
<button class="p-rating-star">☆</button>
<button class="p-rating-star">☆</button>
<button class="p-rating-star">★</button>
</div>
`} `}
css={``}
> >
<div <div
style={{ style={{

View File

@@ -21,7 +21,16 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<div style=" <div class="container">
<!-- Text input -->
<input type="text" class="container__input" />
<!-- Search icon sticks to the left or right -->
...
</div>
`}
css={`
.container {
display: flex; display: flex;
/* If you want to place the icon before the text input */ /* If you want to place the icon before the text input */
@@ -29,22 +38,14 @@ html={`
/* Border */ /* Border */
border: 1px solid rgba(0, 0, 0, 0.3); border: 1px solid rgba(0, 0, 0, 0.3);
"> }
<!-- Text input -->
<input
type="text"
style="
border-color: transparent;
/* Take available width */
flex: 1;
"
/>
<!-- Search icon sticks to the left or right --> .container__input {
... border-color: transparent;
</div> /* Take available width */
flex: 1;
}
`} `}
css={``}
> >
<div <div
style={{ style={{

View File

@@ -22,49 +22,56 @@ const Details: React.FC<{}> = () => {
<div className='p-8 pb-20'> <div className='p-8 pb-20'>
<BrowserFrame <BrowserFrame
html={` html={`
<div style=" <div class="container">
<!-- Left side -->
<!-- Width based on the current value -->
<div class="container__left" style="width: 20%"></div>
<!-- Circle -->
<div class="container__circle"></div>
<!-- Right side -->
<div class="container__right"></div>
</div>
`}
css={`
.container {
/* Content is centered horizontally */ /* Content is centered horizontally */
align-items: center; align-items: center;
display: flex; display: flex;
/* Size */ /* Size */
height: 32px; height: 32px;
"> }
<!-- Left side -->
<div style="
/* Width based on the current value */
height: 2px;
width: 20%;
/* Colors */ .container__left {
background-color: rgba(0, 0, 0, .3); height: 2px;
"></div>
<!-- Circle --> /* Colors */
<div style=" background-color: rgba(0, 0, 0, .3);
/* Size */ }
height: 32px;
width: 32px;
/* Rounded border */ .container__circle {
border-radius: 9999px; /* Size */
height: 32px;
width: 32px;
/* Colors */ /* Rounded border */
background-color: rgba(0, 0, 0, .3); border-radius: 9999px;
"></div>
<!-- Right side --> /* Colors */
<div style=" background-color: rgba(0, 0, 0, .3);
/* Take the remaining width */ }
flex: 1;
height: 2px;
/* Colors */ .container__right {
background-color: rgba(0, 0, 0, .3); /* Take the remaining width */
"></div> flex: 1;
</div> height: 2px;
/* Colors */
background-color: rgba(0, 0, 0, .3);
}
`} `}
css={``}
> >
<div <div
style={{ style={{