2024-04-18 14:15:29 +00:00
|
|
|
import BaseStyle from 'primevue/base/style';
|
|
|
|
|
2024-05-01 08:26:48 +00:00
|
|
|
const theme = ({ dt }) => `
|
|
|
|
.p-toggleswitch {
|
|
|
|
display: inline-block;
|
2024-05-08 10:51:06 +00:00
|
|
|
width: ${dt('toggleswitch.width')};
|
|
|
|
height: ${dt('toggleswitch.height')};
|
2024-05-01 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch-input {
|
|
|
|
cursor: pointer;
|
|
|
|
appearance: none;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
opacity: 0;
|
|
|
|
z-index: 1;
|
|
|
|
outline: 0 none;
|
|
|
|
border-radius: ${dt('toggleswitch.border.radius')};
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch-slider {
|
|
|
|
position: absolute;
|
|
|
|
cursor: pointer;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
2024-05-14 22:26:11 +00:00
|
|
|
border-width: ${dt('toggleswitch.border.width')};
|
|
|
|
border-style: solid;
|
|
|
|
border-color: ${dt('toggleswitch.border.color')};
|
2024-05-01 08:26:48 +00:00
|
|
|
background: ${dt('toggleswitch.background')};
|
2024-05-25 08:18:55 +00:00
|
|
|
transition: background ${dt('toggleswitch.transition.duration')}, color ${dt('toggleswitch.transition.duration')}, border-color ${dt('toggleswitch.transition.duration')}, outline-color ${dt('toggleswitch.transition.duration')}, box-shadow ${dt('toggleswitch.transition.duration')};
|
2024-05-01 08:26:48 +00:00
|
|
|
border-radius: ${dt('toggleswitch.border.radius')};
|
|
|
|
outline-color: transparent;
|
2024-05-08 10:51:06 +00:00
|
|
|
box-shadow: ${dt('toggleswitch.shadow')};
|
2024-05-01 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch-slider:before {
|
|
|
|
position: absolute;
|
|
|
|
content: "";
|
|
|
|
top: 50%;
|
|
|
|
background: ${dt('toggleswitch.handle.background')};
|
2024-05-08 10:51:06 +00:00
|
|
|
width: ${dt('toggleswitch.handle.size')};
|
|
|
|
height: ${dt('toggleswitch.handle.size')};
|
|
|
|
left: ${dt('toggleswitch.gap')};
|
|
|
|
margin-top: calc(-1 * calc(${dt('toggleswitch.handle.size')} / 2));
|
2024-05-01 08:26:48 +00:00
|
|
|
border-radius: ${dt('toggleswitch.handle.border.radius')};
|
2024-05-25 08:18:55 +00:00
|
|
|
transition: all ${dt('toggleswitch.transition.duration')};
|
2024-05-01 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch.p-toggleswitch-checked .p-toggleswitch-slider {
|
|
|
|
background: ${dt('toggleswitch.checked.background')};
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch.p-toggleswitch-checked .p-toggleswitch-slider:before {
|
|
|
|
background: ${dt('toggleswitch.handle.checked.background')};
|
2024-05-08 10:51:06 +00:00
|
|
|
left: calc(${dt('toggleswitch.width')} - calc(${dt('toggleswitch.handle.size')} + ${dt('toggleswitch.gap')}));
|
2024-05-01 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover) .p-toggleswitch-slider {
|
|
|
|
background: ${dt('toggleswitch.hover.background')};
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover) .p-toggleswitch-slider:before {
|
|
|
|
background: ${dt('toggleswitch.handle.hover.background')};
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover).p-toggleswitch-checked .p-toggleswitch-slider {
|
|
|
|
background: ${dt('toggleswitch.checked.hover.background')};
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:hover).p-toggleswitch-checked .p-toggleswitch-slider:before {
|
|
|
|
background: ${dt('toggleswitch.handle.checked.hover.background')};
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch:not(.p-disabled):has(.p-toggleswitch-input:focus-visible) .p-toggleswitch-slider {
|
2024-05-08 10:51:06 +00:00
|
|
|
border-color: ${dt('toggleswitch.focus.border.color')};
|
|
|
|
box-shadow: ${dt('toggleswitch.focus.ring.shadow')};
|
|
|
|
outline: ${dt('toggleswitch.focus.ring.width')} ${dt('toggleswitch.focus.ring.style')} ${dt('toggleswitch.focus.ring.color')};
|
|
|
|
outline-offset: ${dt('toggleswitch.focus.ring.offset')};
|
2024-05-01 08:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.p-toggleswitch.p-invalid > .p-toggleswitch-slider {
|
2024-05-14 22:26:11 +00:00
|
|
|
border-color: ${dt('toggleswitch.invalid.border.color')};
|
2024-05-01 08:26:48 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2024-04-18 14:15:29 +00:00
|
|
|
const inlineStyles = {
|
|
|
|
root: { position: 'relative' }
|
|
|
|
};
|
|
|
|
|
|
|
|
const classes = {
|
|
|
|
root: ({ instance, props }) => [
|
|
|
|
'p-toggleswitch p-component',
|
|
|
|
{
|
|
|
|
'p-toggleswitch-checked': instance.checked,
|
|
|
|
'p-disabled': props.disabled,
|
|
|
|
'p-invalid': props.invalid
|
|
|
|
}
|
|
|
|
],
|
|
|
|
input: 'p-toggleswitch-input',
|
|
|
|
slider: 'p-toggleswitch-slider'
|
|
|
|
};
|
|
|
|
|
|
|
|
export default BaseStyle.extend({
|
|
|
|
name: 'toggleswitch',
|
2024-05-01 08:26:48 +00:00
|
|
|
theme,
|
2024-04-18 14:15:29 +00:00
|
|
|
classes,
|
|
|
|
inlineStyles
|
|
|
|
});
|