@xyhp915/slack-base-ui 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { Link } from 'react-router-dom'
2
+ import clsx from 'clsx'
2
3
  import {
3
4
  ArrowLeft,
4
5
  Bell,
@@ -93,6 +94,7 @@ import { Switch } from '../components/Switch'
93
94
  import { Tabs, TabList, Tab, TabPanel } from '../components/Tabs'
94
95
  import { Progress } from '../components/Progress'
95
96
  import { useToast } from '../components/Toast'
97
+ import type { ToastPosition } from '../components/Toast'
96
98
  import { Loading } from '../components/Loading'
97
99
  import { AutoComplete } from '../components/AutoComplete'
98
100
 
@@ -126,7 +128,7 @@ export const ComponentShowcase = () => {
126
128
  const [switchOn, setSwitchOn] = useState(false)
127
129
  const [notificationsOn, setNotificationsOn] = useState(true)
128
130
  const [progressValue, setProgressValue] = useState(60)
129
- const { toast } = useToast()
131
+ const { toast, position: toastPosition, setPosition: setToastPosition } = useToast()
130
132
 
131
133
  // AutoComplete states
132
134
  const [acValue, setAcValue] = useState('')
@@ -1868,94 +1870,152 @@ export const ComponentShowcase = () => {
1868
1870
  <section className="max-w-5xl mx-auto px-8 pb-16 space-y-6">
1869
1871
  <div className="pb-2 border-b border-(--border-light)">
1870
1872
  <h2 className="text-2xl font-bold text-(--text-primary)">Toast</h2>
1871
- <p className="text-(--text-secondary) mt-1">Lightweight notification toasts with five semantic types.</p>
1873
+ <p className="text-(--text-secondary) mt-1">
1874
+ 轻量通知条,支持五种语义类型和六个显示位置。通过{' '}
1875
+ <code className="text-sm bg-(--bg-secondary) px-1.5 py-0.5 rounded border border-(--border-light) font-mono">useToast()</code>{' '}
1876
+ 命令式调用。
1877
+ </p>
1872
1878
  </div>
1879
+
1873
1880
  <div className="grid grid-cols-1 md:grid-cols-2 gap-10">
1881
+ {/* Types */}
1874
1882
  <div className="space-y-4">
1875
- <h3 className="font-semibold text-(--text-secondary)">Types</h3>
1883
+ <h3 className="font-semibold text-(--text-secondary)">类型 Types</h3>
1876
1884
  <div className="flex flex-wrap gap-3">
1877
1885
  <Button
1878
- size="sm"
1879
- onClick={() => toast(
1880
- { title: 'Default notification', description: 'This is a default toast message.' })}
1886
+ size="sm"
1887
+ onClick={() => toast({ title: 'Default notification', description: 'This is a default toast message.' })}
1881
1888
  >
1882
1889
  Default
1883
1890
  </Button>
1884
1891
  <Button
1885
- size="sm"
1886
- onClick={() => toast(
1887
- { type: 'info', title: 'Info', description: 'Your workspace is being updated.' })}
1892
+ size="sm"
1893
+ onClick={() => toast({ type: 'info', title: 'Info', description: 'Your workspace is being updated.' })}
1888
1894
  >
1889
1895
  Info
1890
1896
  </Button>
1891
1897
  <Button
1892
- size="sm"
1893
- variant="primary"
1894
- onClick={() => toast({
1895
- type: 'success',
1896
- title: 'Message sent!',
1897
- description: 'Your message was delivered to #general.',
1898
- })}
1898
+ size="sm"
1899
+ variant="primary"
1900
+ onClick={() => toast({ type: 'success', title: 'Message sent!', description: 'Your message was delivered to #general.' })}
1899
1901
  >
1900
1902
  Success
1901
1903
  </Button>
1902
1904
  <Button
1903
- size="sm"
1904
- onClick={() => toast({
1905
- type: 'warning',
1906
- title: 'Storage almost full',
1907
- description: 'You have used 90% of your storage.',
1908
- })}
1905
+ size="sm"
1906
+ onClick={() => toast({ type: 'warning', title: 'Storage almost full', description: 'You have used 90% of your storage.' })}
1909
1907
  >
1910
1908
  Warning
1911
1909
  </Button>
1912
1910
  <Button
1913
- size="sm"
1914
- variant="danger"
1915
- onClick={() => toast({
1916
- type: 'error',
1917
- title: 'Failed to send',
1918
- description: 'Could not deliver the message. Try again.',
1919
- })}
1911
+ size="sm"
1912
+ variant="danger"
1913
+ onClick={() => toast({ type: 'error', title: 'Failed to send', description: 'Could not deliver the message. Try again.' })}
1920
1914
  >
1921
1915
  Error
1922
1916
  </Button>
1923
1917
  </div>
1924
1918
  </div>
1919
+
1920
+ {/* With action */}
1925
1921
  <div className="space-y-4">
1926
- <h3 className="font-semibold text-(--text-secondary)">With action</h3>
1922
+ <h3 className="font-semibold text-(--text-secondary)">带操作按钮 With action</h3>
1927
1923
  <div className="flex flex-wrap gap-3">
1928
1924
  <Button
1929
- size="sm"
1930
- onClick={() =>
1931
- toast({
1932
- type: 'info',
1933
- title: 'New message in #general',
1934
- description: 'Alice: "Hey everyone, quick update…"',
1935
- action: {
1936
- label: 'View',
1937
- onClick: () => {},
1938
- },
1939
- })
1940
- }
1925
+ size="sm"
1926
+ onClick={() =>
1927
+ toast({
1928
+ type: 'info',
1929
+ title: 'New message in #general',
1930
+ description: 'Alice: "Hey everyone, quick update…"',
1931
+ action: { label: 'View', onClick: () => {} },
1932
+ })
1933
+ }
1941
1934
  >
1942
1935
  Notification with action
1943
1936
  </Button>
1944
1937
  <Button
1945
- size="sm"
1946
- onClick={() =>
1947
- toast({
1948
- type: 'success',
1949
- title: 'Invite sent',
1950
- description: 'bob@example.com will receive an invitation.',
1951
- timeout: 8000,
1952
- })
1953
- }
1938
+ size="sm"
1939
+ onClick={() =>
1940
+ toast({
1941
+ type: 'success',
1942
+ title: 'Invite sent',
1943
+ description: 'bob@example.com will receive an invitation.',
1944
+ timeout: 8000,
1945
+ })
1946
+ }
1954
1947
  >
1955
1948
  Custom timeout (8s)
1956
1949
  </Button>
1957
1950
  </div>
1958
1951
  </div>
1952
+
1953
+ {/* Position picker — spans full width */}
1954
+ <div className="space-y-4 md:col-span-2">
1955
+ <h3 className="font-semibold text-(--text-secondary)">自定义位置 Position</h3>
1956
+ <p className="text-sm text-(--text-secondary)">
1957
+ 可在 <code className="text-xs bg-(--bg-secondary) px-1 py-0.5 rounded border border-(--border-light) font-mono">&lt;ToastProvider position="…"&gt;</code> 设置默认位置,
1958
+ 或运行时通过 <code className="text-xs bg-(--bg-secondary) px-1 py-0.5 rounded border border-(--border-light) font-mono">setPosition()</code> 动态切换。
1959
+ 点击下方格子即可预览对应位置。
1960
+ </p>
1961
+
1962
+ {/* Visual 3×2 position grid */}
1963
+ <div className="relative w-full h-44 rounded-xl border-2 border-dashed border-(--border-light) bg-(--bg-muted) overflow-hidden">
1964
+ {/* 3 cols × 2 rows grid */}
1965
+ <div className="absolute inset-0 grid grid-cols-3 grid-rows-2">
1966
+ {(
1967
+ [
1968
+ ['top-left', '↖', 'top-left'],
1969
+ ['top-center', '↑', 'top-center'],
1970
+ ['top-right', '↗', 'top-right'],
1971
+ ['bottom-left', '↙', 'bottom-left'],
1972
+ ['bottom-center','↓', 'bottom-center'],
1973
+ ['bottom-right', '↘', 'bottom-right'],
1974
+ ] as [ToastPosition, string, string][]
1975
+ ).map(([pos, arrow]) => {
1976
+ const active = toastPosition === pos
1977
+ return (
1978
+ <button
1979
+ key={pos}
1980
+ onClick={() => {
1981
+ setToastPosition(pos)
1982
+ toast({
1983
+ type: 'info',
1984
+ title: pos,
1985
+ description: `Toast 显示在 ${pos}`,
1986
+ timeout: 3000,
1987
+ })
1988
+ }}
1989
+ className={clsx(
1990
+ 'relative flex flex-col items-center justify-center gap-1 transition-all duration-150',
1991
+ 'border border-(--border-light) text-xs font-medium',
1992
+ active
1993
+ ? 'bg-(--accent-action) text-(--accent-contrast) font-semibold shadow-inner'
1994
+ : 'text-(--text-muted) hover:bg-(--bg-hover) hover:text-(--text-primary)',
1995
+ )}
1996
+ >
1997
+ <span className="text-xl leading-none">{arrow}</span>
1998
+ <span className="text-[10px] opacity-80 px-1 text-center leading-tight">
1999
+ {pos.replace('-', '\u00A0')}
2000
+ </span>
2001
+ </button>
2002
+ )
2003
+ })}
2004
+ </div>
2005
+
2006
+ {/* Center label */}
2007
+ <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
2008
+ <span className="text-[11px] text-(--text-muted) select-none px-2 py-1 bg-(--bg-muted)/80 rounded">
2009
+ 点击格子切换位置
2010
+ </span>
2011
+ </div>
2012
+ </div>
2013
+
2014
+ <p className="text-xs text-(--text-muted)">
2015
+ 当前位置:
2016
+ <span className="font-semibold text-(--text-primary) ml-1">{toastPosition}</span>
2017
+ </p>
2018
+ </div>
1959
2019
  </div>
1960
2020
  </section>
1961
2021