import React, { useState } from 'react'; import { View, Text, StyleSheet, ScrollView, Pressable, Platform, } from 'react-native'; import { useUx4gTheme } from '../theme/Ux4gThemeContext'; import { UX4GColors } from '../foundation/colors'; import { Ux4gFab, Ux4gFabVariant, Ux4gFabColorTheme, Ux4gFabPosition, Ux4gFabActionItem, } from '../components/fab'; export const FabShowcase: React.FC = () => { const theme = useUx4gTheme(); const [toastMessage, setToastMessage] = useState(''); // Floating FAB Playground Controls const [isFloatEnabled, setIsFloatEnabled] = useState(true); const [floatVariant, setFloatVariant] = useState('menu-labelled'); const [floatTheme, setFloatTheme] = useState('brand'); const [floatPosition, setFloatPosition] = useState('bottom-right'); const [floatBackdrop, setFloatBackdrop] = useState(true); // Matrix Interactive States (Controlled open/close on click) const [matrixExpanded, setMatrixExpanded] = useState(true); const [brandJoinedOpen, setBrandJoinedOpen] = useState(true); const [surfaceJoinedOpen, setSurfaceJoinedOpen] = useState(true); const [brandSpacedOpen, setBrandSpacedOpen] = useState(true); const [surfaceSpacedOpen, setSurfaceSpacedOpen] = useState(true); const [brandLabelledOpen, setBrandLabelledOpen] = useState(true); const [surfaceLabelledOpen, setSurfaceLabelledOpen] = useState(true); const triggerToast = (msg: string) => { setToastMessage(msg); setTimeout(() => { setToastMessage(''); }, 2500); }; const actionItems: Ux4gFabActionItem[] = [ { id: 'add', label: 'Add', icon: 'plus', onPress: () => triggerToast('Action: Add tapped!') }, { id: 'message', label: 'Message', icon: 'message', onPress: () => triggerToast('Action: Message tapped!') }, { id: 'share', label: 'Share', icon: 'share', onPress: () => triggerToast('Action: Share tapped!') }, { id: 'call', label: 'Call', icon: 'call', onPress: () => triggerToast('Action: Call tapped!') }, ]; const cardStyle = [ styles.card, { backgroundColor: theme.isDark ? UX4GColors.neutral900 : UX4GColors.white, borderColor: theme.isDark ? UX4GColors.neutral800 : UX4GColors.neutral200, }, ]; const toggleAllMatrix = () => { const nextState = !matrixExpanded; setMatrixExpanded(nextState); setBrandJoinedOpen(nextState); setSurfaceJoinedOpen(nextState); setBrandSpacedOpen(nextState); setSurfaceSpacedOpen(nextState); setBrandLabelledOpen(nextState); setSurfaceLabelledOpen(nextState); }; return ( {/* Floating FAB on top of screen stack */} {isFloatEnabled && ( { if (floatVariant === 'icon' || floatVariant === 'labelled') { triggerToast(`Floating FAB (${floatVariant}) Clicked!`); } }} onToggle={(open) => { triggerToast(open ? 'Speed-Dial Menu Opened' : 'Speed-Dial Menu Closed'); }} /> )} {/* Header */} Floating Action Button (FAB) High-priority floating trigger and speed-dial actions. Click any button below to open/close menu items, or test the live floating FAB on the screen! {/* Live Floating Status Alert */} {toastMessage ? ( 🔔 {toastMessage} ) : null} {/* Live Screen Overlay Controller Card */} 🚀 Live Floating Overlay (Top of Stack) Experience how the FAB floats fixed over scrollable screen content with speed-dial animations. {/* Controls */} {/* Toggle Float */} Floating Button setIsFloatEnabled(true)} style={[ styles.chip, isFloatEnabled && styles.activeChip, ]} > Visible (Active) setIsFloatEnabled(false)} style={[ styles.chip, !isFloatEnabled && styles.activeChip, ]} > Hidden {/* Select Variant */} Variant {(['menu-labelled', 'menu-spaced', 'menu-joined', 'icon', 'labelled'] as Ux4gFabVariant[]).map((v) => ( setFloatVariant(v)} style={[ styles.chip, floatVariant === v && styles.activeChip, ]} > {v} ))} {/* Select Theme & Position */} Theme setFloatTheme('brand')} style={[styles.chip, floatTheme === 'brand' && styles.activeChip]} > Brand setFloatTheme('surface')} style={[styles.chip, floatTheme === 'surface' && styles.activeChip]} > Surface Position setFloatPosition('bottom-right')} style={[styles.chip, floatPosition === 'bottom-right' && styles.activeChip]} > Right setFloatPosition('bottom-left')} style={[styles.chip, floatPosition === 'bottom-left' && styles.activeChip]} > Left {/* Complete Design Matrix Section (Matching User Reference Image) */} 📐 Design System Matrix Click any FAB button to test expanding and collapsing menu speed-dials. {matrixExpanded ? 'Collapse All' : 'Expand All'} {/* Matrix Headers */} Brand Surface {/* Row 1: Icon */} Icon triggerToast('Brand Icon FAB pressed')} /> triggerToast('Surface Icon FAB pressed')} /> {/* Row 2: Labelled */} Labelled triggerToast('Brand Labelled FAB pressed')} /> triggerToast('Surface Labelled FAB pressed')} /> {/* Row 3: Menu - joined */} Menu - joined setBrandJoinedOpen(open)} actions={actionItems} /> setSurfaceJoinedOpen(open)} actions={actionItems} /> {/* Row 4: Menu - spaced */} Menu - spaced setBrandSpacedOpen(open)} actions={actionItems} /> setSurfaceSpacedOpen(open)} actions={actionItems} /> {/* Row 5: Menu - labelled */} Menu - labelled setBrandLabelledOpen(open)} actions={actionItems} /> setSurfaceLabelledOpen(open)} actions={actionItems} /> ); }; const styles = StyleSheet.create({ outerWrapper: { flex: 1, position: 'relative', }, container: { flex: 1, }, contentContainer: { padding: 16, paddingBottom: 110, }, header: { paddingBottom: 16, marginBottom: 16, borderBottomWidth: 1, }, title: { fontSize: 24, fontWeight: '700', marginBottom: 6, }, subtitle: { fontSize: 14, lineHeight: 20, }, toastBanner: { backgroundColor: '#1E293B', paddingVertical: 12, paddingHorizontal: 16, borderRadius: 10, marginBottom: 16, alignItems: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.15, shadowRadius: 4, elevation: 3, }, toastText: { color: '#F8FAFC', fontSize: 14, fontWeight: '600', }, card: { borderRadius: 16, borderWidth: 1, padding: 16, marginBottom: 20, }, cardHeaderRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 14, }, sectionTitle: { fontSize: 17, fontWeight: '700', marginBottom: 4, }, sectionSubtitle: { fontSize: 13, lineHeight: 18, }, toggleAllBtn: { backgroundColor: '#EEF2FF', paddingHorizontal: 12, paddingVertical: 6, borderRadius: 8, }, toggleAllText: { color: UX4GColors.primary, fontSize: 12, fontWeight: '700', }, // Controls controlsGrid: { marginTop: 8, gap: 14, }, controlGroup: { gap: 6, }, controlLabel: { fontSize: 13, fontWeight: '600', }, chipRow: { flexDirection: 'row', alignItems: 'center', gap: 8, }, rowControls: { flexDirection: 'row', alignItems: 'center', gap: 12, }, chip: { paddingHorizontal: 14, paddingVertical: 8, borderRadius: 20, backgroundColor: '#F1F5F9', borderWidth: 1, borderColor: '#E2E8F0', }, activeChip: { backgroundColor: UX4GColors.primary, borderColor: UX4GColors.primary, }, chipText: { fontSize: 13, fontWeight: '600', color: '#475569', }, activeChipText: { color: '#FFFFFF', }, // Matrix Styles matrixHeaderRow: { flexDirection: 'row', alignItems: 'center', paddingBottom: 12, borderBottomWidth: 1, borderBottomColor: '#E2E8F0', marginBottom: 14, }, rowLabelCell: { width: 96, justifyContent: 'center', }, rowLabelText: { fontSize: 13, fontWeight: '600', }, matrixHeaderCell: { flex: 1, alignItems: 'center', }, columnHeaderText: { fontSize: 16, fontWeight: '700', marginBottom: 6, }, brandIndicator: { width: 60, height: 3, backgroundColor: '#C0B3FF', borderRadius: 2, }, surfaceIndicator: { width: 60, height: 3, backgroundColor: '#E2E8F0', borderRadius: 2, }, matrixRow: { flexDirection: 'row', alignItems: 'flex-end', paddingVertical: 14, }, tallRow: { paddingVertical: 20, }, extraTallRow: { paddingVertical: 24, }, matrixCell: { flex: 1, alignItems: 'center', justifyContent: 'flex-end', }, matrixDivider: { height: 1, backgroundColor: '#F1F5F9', marginVertical: 4, }, });