formulaire-dynamique
Version:
Package React pour formulaires dynamiques avec validation et tous types de champs
362 lines (307 loc) • 5.58 kB
CSS
.dynamic-form {
max-width: 600px;
margin: 0 auto;
padding: 20px;
font-family: Arial, sans-serif;
}
.form-field-container {
margin-bottom: 20px;
}
.field-label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-field {
width: 100%;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box;
}
.form-field.error {
border-color: #ff4444;
}
.error-message {
color: #ff4444;
font-size: 14px;
margin-top: 5px;
}
.required-asterisk {
color: #ff4444;
margin-left: 3px;
}
/* Styles pour les icônes */
.field-icon {
display: inline-flex;
align-items: center;
color: #666;
font-size: 16px;
margin-right: 8px;
}
.field-icon.icon-image {
margin-right: 8px;
}
.input-with-icon {
display: flex;
align-items: center;
position: relative;
}
.input-with-icon .form-field {
padding-left: 35px;
}
.input-with-icon .field-icon {
position: absolute;
left: 10px;
z-index: 1;
pointer-events: none;
}
.textarea-with-icon {
display: flex;
align-items: flex-start;
position: relative;
}
.textarea-with-icon .form-field {
padding-left: 35px;
}
.textarea-with-icon .field-icon {
position: absolute;
left: 10px;
top: 12px;
z-index: 1;
pointer-events: none;
}
.select-with-icon {
display: flex;
align-items: center;
position: relative;
}
.select-with-icon .form-field {
padding-left: 35px;
}
.select-with-icon .field-icon {
position: absolute;
left: 10px;
z-index: 1;
pointer-events: none;
}
.checkbox-with-icon {
display: flex;
align-items: center;
gap: 8px;
}
.checkbox-with-icon input[type="checkbox"] {
width: auto;
margin: 0;
}
.range-container {
display: flex;
align-items: center;
gap: 10px;
}
.range-value {
min-width: 30px;
text-align: center;
font-weight: bold;
}
.radio-group {
display: flex;
flex-direction: column;
gap: 8px;
}
.radio-option {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.radio-option input[type="radio"] {
width: auto;
margin: 0;
}
.option-icon {
display: inline-flex;
align-items: center;
font-size: 14px;
}
.checkbox-label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
font-weight: bold;
}
.checkbox-label input[type="checkbox"] {
width: auto;
margin: 0;
}
.checkbox-text {
display: flex;
align-items: center;
}
/* Styles pour les fichiers et aperçus d'images */
.file-input-container {
display: flex;
flex-direction: column;
gap: 10px;
}
.file-input-wrapper {
display: flex;
align-items: center;
position: relative;
}
.file-input-wrapper .field-icon {
position: absolute;
left: 10px;
z-index: 1;
pointer-events: none;
}
.file-input-wrapper .form-field.file {
padding: 4px;
padding-left: 35px;
}
.image-preview {
position: relative;
display: inline-block;
border: 2px solid #ddd;
border-radius: 8px;
padding: 8px;
background-color: #f9f9f9;
}
.preview-image {
display: block;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.remove-preview {
position: absolute;
top: -5px;
right: -5px;
background-color: #ff4444;
color: white;
border: none;
border-radius: 50%;
width: 20px;
height: 20px;
font-size: 14px;
line-height: 1;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
}
.remove-preview:hover {
background-color: #dd0000;
}
.file-info {
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
background-color: #f5f5f5;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
.file-name {
font-weight: bold;
color: #333;
}
.file-size {
color: #666;
font-style: italic;
}
.remove-file {
background-color: #ff4444;
color: white;
border: none;
border-radius: 50%;
width: 18px;
height: 18px;
font-size: 12px;
line-height: 1;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
margin-left: auto;
}
.remove-file:hover {
background-color: #dd0000;
}
.form-submit-button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.form-submit-button:hover:not(:disabled) {
background-color: #45a049;
}
.form-submit-button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
.help-text {
font-size: 12px;
color: #666;
margin-top: 5px;
font-style: italic;
}
.form-error {
color: #ff4444;
padding: 20px;
border: 1px solid #ff4444;
border-radius: 4px;
background-color: #fff5f5;
text-align: center;
font-weight: bold;
}
.form-field:focus {
outline: 2px solid #4CAF50;
outline-offset: 2px;
}
.form-field.file {
padding: 4px;
}
@media (max-width: 600px) {
.dynamic-form {
padding: 15px;
margin: 0 10px;
}
.range-container {
flex-direction: column;
align-items: flex-start;
}
.input-with-icon,
.textarea-with-icon,
.select-with-icon {
flex-direction: column;
align-items: flex-start;
}
.input-with-icon .form-field,
.textarea-with-icon .form-field,
.select-with-icon .form-field {
padding-left: 12px;
}
.input-with-icon .field-icon,
.textarea-with-icon .field-icon,
.select-with-icon .field-icon {
position: static;
margin-bottom: 5px;
}
.image-preview {
align-self: center;
}
.preview-image {
max-width: 150px ;
max-height: 150px ;
}
}