diff --git a/src/__internal__/checkable-input/checkable-input.style.ts b/src/__internal__/checkable-input/checkable-input.style.ts index 2b131b44a5..d14ce3d884 100644 --- a/src/__internal__/checkable-input/checkable-input.style.ts +++ b/src/__internal__/checkable-input/checkable-input.style.ts @@ -2,10 +2,11 @@ import styled, { css } from "styled-components"; import FieldHelpStyle from "../field-help/field-help.style"; import { FieldLineStyle } from "../form-field/form-field.style"; -import HiddenCheckableInputStyle from "./hidden-checkable-input.style"; import LabelStyle, { StyledLabelContainer } from "../label/label.style"; -import StyledHelp from "../../components/help/help.style"; import StyledValidationIcon from "../validations/validation-icon.style"; +import StyledHelp from "../../components/help/help.style"; + +import HiddenCheckableInputStyle from "./hidden-checkable-input.style"; const StyledCheckableInput = styled.div` display: inline-block; @@ -30,6 +31,12 @@ const StyledCheckableInputWrapper = styled.div labelInline, reverse, }) => css` + /* ${inputWidth !== undefined && + inputWidth !== 0 && + css` */ + width: 100% !important; + /* `} */ + ${FieldLineStyle} { display: flex; } @@ -105,6 +112,7 @@ const StyledCheckableInputWrapper = styled.div css` ${StyledCheckableInput} { width: ${inputWidth}% !important; + min-width: 67px; } `} diff --git a/src/components/switch/__internal__/switch-slider.style.ts b/src/components/switch/__internal__/switch-slider.style.ts index 23af25ed2b..b00e8bbccb 100644 --- a/src/components/switch/__internal__/switch-slider.style.ts +++ b/src/components/switch/__internal__/switch-slider.style.ts @@ -141,7 +141,7 @@ const StyledSwitchSlider = styled.div` error && !disabled && css` - border-color: var(--colorsSemanticNegative450); + border-color: var(--colorsSemanticNegative500); ` } diff --git a/src/components/switch/switch.component.tsx b/src/components/switch/switch.component.tsx index 11bc110710..1a12afb658 100644 --- a/src/components/switch/switch.component.tsx +++ b/src/components/switch/switch.component.tsx @@ -251,10 +251,23 @@ export const Switch = React.forwardRef( ); } - const errorMargin = labelInline && (error || warning) ? 3 : 1; + const defaultMargin = labelInline ? 1 : 0; + const errorMargin = error || warning ? 3 : defaultMargin; const direction = labelInline ? "row" : "column"; const reverseDirection = labelInline ? "row-reverse" : "column"; + let requestedInputWidth = rest.inputWidth; + if ( + requestedInputWidth && + requestedInputWidth <= 1 && + requestedInputWidth >= 0 + ) + requestedInputWidth *= 100; + const enforcedInputWidth = + requestedInputWidth && typeof requestedInputWidth === "number" + ? `${requestedInputWidth}%` + : rest.inputWidth; + return ( <> @@ -264,34 +277,38 @@ export const Switch = React.forwardRef( flexWrap="wrap" alignItems="flex-start" flexDirection={!reverse ? reverseDirection : direction} + width={labelInline ? "100%" : "auto"} > - - - {labelHelp && ( - - {labelHelp} - - )} - + {label} + {labelHelp && ( + + {labelHelp} + + )} + + diff --git a/src/components/switch/switch.mdx b/src/components/switch/switch.mdx index 9b5b311ebb..92156f43ef 100644 --- a/src/components/switch/switch.mdx +++ b/src/components/switch/switch.mdx @@ -177,6 +177,13 @@ The folowing examples use the new validation pattern that is available by settin name="single switch - inline validation with options" /> +#### With optional props and custom widths + + + #### With error { NewValidationInlineDefaultWithOptions.storyName = "New Validation - Inline with options"; +export const NewValidationInlineDefaultWithOptionsAndCustomWidths: Story = () => { + return ( + + + + + + + + ); +}; +NewValidationInlineDefaultWithOptionsAndCustomWidths.storyName = + "New Validation - Inline with options and custom widths"; + export const NewValidationInlineError: Story = () => { return (