Skip to content

Commit

Permalink
feat(tabs): css changes (#2431)
Browse files Browse the repository at this point in the history
part of #2295
  • Loading branch information
Barsnes authored Sep 17, 2024
1 parent c2b78ed commit 3451704
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 66 deletions.
6 changes: 6 additions & 0 deletions .changeset/purple-berries-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@digdir/designsystemet-css": patch
"@digdir/designsystemet-react": patch
---

Tabs: css changes
96 changes: 47 additions & 49 deletions packages/css/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@
--dsc-tabs-content-padding: var(--ds-spacing-5);
--dsc-tabs-content-color: var(--ds-color-neutral-text-default);
--dsc-tabs-list-border-color: var(--ds-color-neutral-border-subtle);

&[data-size='sm'] {
--dsc-tabs-tab-padding: var(--ds-spacing-2) var(--ds-spacing-4);
--dsc-tabs-content-padding: var(--ds-spacing-4);
}

&[data-size='lg'] {
--dsc-tabs-tab-padding: var(--ds-spacing-4) var(--ds-spacing-6);
--dsc-tabs-content-padding: var(--ds-spacing-6);
}
}

.ds-tabs__content {
padding: var(--dsc-tabs-content-padding);
color: var(--dsc-tabs-content-color);
}

.ds-tabs__tablist {
display: flex;
flex-direction: row;
border-bottom: var(--ds-border-width-default) solid var(--dsc-tabs-list-border-color);
position: relative;
}

.ds-tabs__tab {
Expand All @@ -23,59 +45,35 @@
color: var(--dsc-tabs-tab-color);
position: relative;
font-family: inherit;
}

.ds-tabs__content {
padding: var(--dsc-tabs-content-padding);
color: var(--dsc-tabs-content-color);
}

.ds-tabs--sm {
--dsc-tabs-tab-padding: var(--ds-spacing-2) var(--ds-spacing-4);
--dsc-tabs-content-padding: var(--ds-spacing-4);
}

.ds-tabs--md {
--dsc-tabs-tab-padding: var(--ds-spacing-3) var(--ds-spacing-5);
--dsc-tabs-content-padding: var(--ds-spacing-5);
}

.ds-tabs--lg {
--dsc-tabs-tab-padding: var(--ds-spacing-4) var(--ds-spacing-6);
--dsc-tabs-content-padding: var(--ds-spacing-6);
}

@media (hover: hover) and (pointer: fine) {
.ds-tabs__tab:hover:not([aria-selected='true']) {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-neutral-border-subtle);
--dsc-tabs-tab-color: var(--ds-color-neutral-text-default);
&[aria-selected='true'] {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-accent-base-default);
--dsc-tabs-tab-color: var(--ds-color-accent-text-subtle);
}
}

.ds-tabs__tab[aria-selected='true'] {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-accent-base-default);
--dsc-tabs-tab-color: var(--ds-color-accent-text-subtle);
}
@composes ds-focus from './utilities.css';

.ds-tabs__tab:focus {
z-index: 2;
}
/* We set z-index to make sure the active line does not bleed over the focus indicator */
&:focus-visible {
z-index: 2;
}

.ds-tabs__tab::after {
content: '';
display: block;
height: 3px;
width: 100%;
border-radius: var(--dsc-border-radius-full);
background-color: var(--dsc-tabs__tab-bottom-border-color);
position: absolute;
bottom: 0;
left: 0;
}
&::after {
content: '';
display: block;
height: 3px;
width: 100%;
border-radius: var(--dsc-border-radius-full);
background-color: var(--dsc-tabs__tab-bottom-border-color);
position: absolute;
bottom: 0;
left: 0;
}

.ds-tabs__tablist {
display: flex;
flex-direction: row;
border-bottom: var(--ds-border-width-default) solid var(--dsc-tabs-list-border-color);
position: relative;
@media (hover: hover) and (pointer: fine) {
&:hover:not([aria-selected='true']) {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-neutral-border-subtle);
--dsc-tabs-tab-color: var(--ds-color-neutral-text-default);
}
}
}
2 changes: 1 addition & 1 deletion packages/react/src/components/Tabs/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Tab = forwardRef<HTMLButtonElement, TabProps>((props, ref) => {
<button
{...useTabRest}
type='button'
className={cl('ds-tabs__tab', 'ds-focus', className)}
className={cl('ds-tabs__tab', className)}
ref={ref}
>
{children}
Expand Down
20 changes: 4 additions & 16 deletions packages/react/src/components/Tabs/TabsRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,7 @@ export const TabsContext = createContext<TabsContextProps>({});
* ```
*/
export const TabsRoot = forwardRef<HTMLDivElement, TabsProps>(
(
{
size = 'md',
children,
value,
defaultValue,
className,
onChange,
...rest
},
ref,
) => {
({ size = 'md', value, defaultValue, className, onChange, ...rest }, ref) => {
const isControlled = value !== undefined;
const [uncontrolledValue, setUncontrolledValue] = useState<
string | undefined
Expand All @@ -77,12 +66,11 @@ export const TabsRoot = forwardRef<HTMLDivElement, TabsProps>(
}}
>
<div
className={cl('ds-tabs', `ds-tabs--${size}`, className)}
className={cl('ds-tabs', className)}
data-size={size}
ref={ref}
{...rest}
>
{children}
</div>
/>
</TabsContext.Provider>
);
},
Expand Down

0 comments on commit 3451704

Please sign in to comment.