|
3 | 3 | * All styles mapped from Figma Forsured Design System |
4 | 4 | */ |
5 | 5 |
|
| 6 | +import { Platform } from 'react-native' |
6 | 7 | import type { ViewStyle, TextStyle } from 'react-native' |
7 | 8 | import { colors } from '../../tokens/colors' |
8 | 9 | import type { ResolvedThemeMode } from '../../tokens/colors' |
9 | 10 | import { borderRadius } from '../../tokens/borders' |
10 | 11 | import { spacing } from '../../tokens/spacing' |
11 | | -import { typography } from '../../tokens/typography' |
| 12 | +import { fontWeight, typography } from '../../tokens/typography' |
12 | 13 | import { boxShadows } from '../../tokens/shadows' |
13 | 14 | import type { TabType, TabColor, TabSize, TabOrientation, TabStyleConfig } from './Tabs.types' |
14 | 15 |
|
@@ -79,7 +80,7 @@ export function getTabListStyles( |
79 | 80 | options?: { gap?: number; wrap?: boolean; type?: TabType } |
80 | 81 | ): ViewStyle { |
81 | 82 | const folder = options?.type === 'folder' && orientation === 'horizontal' |
82 | | - const gap = options?.gap ?? (orientation === 'horizontal' ? (folder ? spacing[4] : spacing[8]) : 0) |
| 83 | + const gap = options?.gap ?? (orientation === 'horizontal' ? (folder ? spacing[2] : spacing[8]) : 0) |
83 | 84 | return { |
84 | 85 | flexDirection: orientation === 'horizontal' ? 'row' : 'column', |
85 | 86 | alignItems: orientation === 'horizontal' ? (folder ? 'flex-end' : 'flex-start') : 'stretch', |
@@ -174,6 +175,7 @@ export function getTabTriggerStyles( |
174 | 175 | let borderRightWidth: number | undefined |
175 | 176 | let borderRightColor: string | undefined |
176 | 177 | let boxShadow: string | undefined |
| 178 | + let backdrop: ViewStyle | undefined |
177 | 179 |
|
178 | 180 | // Determine colors based on state |
179 | 181 | if (isDisabled) { |
@@ -258,22 +260,54 @@ export function getTabTriggerStyles( |
258 | 260 | backgroundColor = colors.bg[theme].subtle |
259 | 261 | } |
260 | 262 | } else if (type === 'folder') { |
261 | | - // Folder type: a bordered tab with rounded top corners. The strip draws |
262 | | - // the hairline (see getTabListStyles); the selected tab overlaps it by one |
263 | | - // pixel and paints its own bottom edge in the surface colour, so the tab |
264 | | - // and the panel below read as one shape. Unselected tabs sit on the |
265 | | - // subtle ground a step back. |
266 | | - container.borderWidth = 1 |
267 | | - container.borderColor = colors.border[theme].default |
268 | | - container.borderTopLeftRadius = borderRadius.l |
269 | | - container.borderTopRightRadius = borderRadius.l |
| 263 | + // Folder type — the SCF prototype's tab: a bordered shape with rounded |
| 264 | + // top corners, leaning back very slightly (perspective 12px, 1.4° about |
| 265 | + // its bottom edge) so the row reads as index-card tabs rather than |
| 266 | + // buttons. The shape is a layer behind the label (`backdrop`), so the |
| 267 | + // label stays flat; the strip draws the hairline (see getTabListStyles), |
| 268 | + // the selected tab overlaps it by a pixel and paints its own bottom edge |
| 269 | + // in the panel colour, so tab and panel read as one surface. Unselected |
| 270 | + // tabs sit on the ground a step back, with an inset shadow at the foot on |
| 271 | + // web; hovering lifts one to the panel colour. |
| 272 | + // |
| 273 | + // Typography follows the prototype's folder tabs: the heading face at |
| 274 | + // body size, medium weight, accent when selected and the secondary text |
| 275 | + // colour otherwise. |
| 276 | + const selected = isSelected && !isDisabled |
| 277 | + container.paddingHorizontal = spacing[24] |
| 278 | + container.paddingVertical = spacing[8] |
| 279 | + container.height = undefined |
| 280 | + container.minHeight = undefined |
270 | 281 | container.marginBottom = -1 |
271 | | - if (isSelected && !isDisabled) { |
272 | | - backgroundColor = colors.bg[theme].default |
273 | | - container.borderBottomColor = colors.bg[theme].default |
274 | | - } else { |
275 | | - backgroundColor = isHovered && !isDisabled ? colors.bg[theme].default : colors.bg[theme].subtle |
| 282 | + container.zIndex = selected ? 2 : 1 |
| 283 | + text.fontFamily = typography.h5.fontFamily |
| 284 | + text.fontWeight = fontWeight.medium |
| 285 | + // Accent-700 on the light panel; on the dark ground the same step is |
| 286 | + // near-invisible, so the selected label takes the ramp's light step. |
| 287 | + textColor = isDisabled |
| 288 | + ? colors.text[theme].disabled |
| 289 | + : selected |
| 290 | + ? theme === 'dark' |
| 291 | + ? colors.primary[300] |
| 292 | + : colors.primary[700] |
| 293 | + : colors.text[theme].secondary |
| 294 | + iconColor = textColor |
| 295 | + backdrop = { |
| 296 | + borderWidth: 1, |
| 297 | + borderColor: colors.border[theme].default, |
| 298 | + borderTopLeftRadius: borderRadius.l, |
| 299 | + borderTopRightRadius: borderRadius.l, |
| 300 | + borderBottomWidth: selected ? 1 : 0, |
| 301 | + borderBottomColor: colors.bg[theme].default, |
| 302 | + backgroundColor: |
| 303 | + selected || (isHovered && !isDisabled) ? colors.bg[theme].default : colors.bg[theme].subtle, |
| 304 | + transform: [{ perspective: 12 }, { rotateX: '1.4deg' }], |
| 305 | + transformOrigin: 'bottom', |
| 306 | + ...(Platform.OS === 'web' && { |
| 307 | + boxShadow: selected ? boxShadows.folderTabSelected : boxShadows.folderTab, |
| 308 | + }), |
276 | 309 | } |
| 310 | + backgroundColor = 'transparent' |
277 | 311 | borderBottomWidth = undefined |
278 | 312 | borderRightWidth = undefined |
279 | 313 | } else if (type === 'shadow') { |
@@ -318,6 +352,7 @@ export function getTabTriggerStyles( |
318 | 352 | container, |
319 | 353 | text, |
320 | 354 | iconColor, |
| 355 | + ...(backdrop && { backdrop }), |
321 | 356 | } |
322 | 357 | } |
323 | 358 |
|
|
0 commit comments