CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-keystone-ui--core

Core design system components and utilities for KeystoneJS applications

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

@keystone-ui/core

@keystone-ui/core is a foundational design system library that provides core UI primitives, theming capabilities, and layout components for building KeystoneJS applications. Built on React and Emotion, it offers a comprehensive set of components with responsive design support, accessibility features, and a complete theme system.

Package Information

  • Package Name: @keystone-ui/core
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @keystone-ui/core

Core Imports

import { Box, Text, Stack, Core, useTheme } from "@keystone-ui/core";

For CommonJS:

const { Box, Text, Stack, Core, useTheme } = require("@keystone-ui/core");

Basic Usage

import { Core, Box, Text, Stack, ThemeProvider } from "@keystone-ui/core";

// Import the default theme from its specific location
// Note: The default theme is not exported from the main package entry point
// You need to import it directly from the themes directory
import { theme } from "@keystone-ui/core/themes/default";

// Or create your own theme following this structure
const customTheme = {
  spacing: { medium: 16, large: 24 },
  colors: { neutral100: '#f5f5f5', neutral700: '#6b7280' },
  radii: { medium: 8 },
  typography: { fontSize: { large: '1.125rem' }, fontWeight: { bold: 700 } }
};

function App() {
  return (
    <ThemeProvider theme={theme}>
      <Core>
        <Stack gap="medium">
          <Box padding="large" background="neutral100" rounding="medium">
            <Text size="large" weight="bold">Welcome</Text>
            <Text color="neutral700">
              This is a simple example using @keystone-ui/core components.
            </Text>
          </Box>
        </Stack>
      </Core>
    </ThemeProvider>
  );
}

Architecture

@keystone-ui/core is built around several key architectural principles:

  • Polymorphic Components: Most components support an as prop allowing you to change the underlying element or component
  • Responsive Design: Components accept responsive prop values as arrays or objects that map to breakpoints
  • Theme Integration: All components automatically consume theme values through React Context
  • Emotion CSS-in-JS: Built on Emotion for performant, dynamic styling with excellent TypeScript support
  • Design System Foundation: Complete design token system including colors, spacing, typography, and breakpoints

Capabilities

Layout Components

Fundamental layout primitives for building flexible, responsive interfaces with consistent spacing and alignment.

// Core layout component with comprehensive styling props
function Box(props: BoxProps): JSX.Element;

// Flexible vertical/horizontal layout with gaps and dividers
function Stack(props: StackProps): JSX.Element;

// Horizontal layout with wrapping support
function Inline(props: InlineProps): JSX.Element;

interface BoxProps {
  // Color props
  background?: ResponsiveProp<keyof Theme['palette']>;
  foreground?: ResponsiveProp<keyof Theme['palette']>;
  
  // Spacing props
  margin?: ResponsiveProp<keyof Theme['spacing']>;
  padding?: ResponsiveProp<keyof Theme['spacing']>;
  
  // Border radius props
  rounding?: ResponsiveProp<keyof Theme['radii']>;
  
  // Layout props
  width?: ResponsiveProp<string | number>;
  height?: ResponsiveProp<string | number>;
  textAlign?: ResponsiveProp<'left' | 'right' | 'center' | 'justify'>;
  
  // Polymorphic as prop
  as?: ElementType;
}

Layout Components

Typography Components

Typography components with theme-integrated styling and semantic heading support.

// Text component with typography controls
function Text(props: TextProps): JSX.Element;

// Generic heading component
function Heading(props: HeadingProps): JSX.Element;

// Specific heading level components
function H1(props: BoxProps): JSX.Element;
function H2(props: BoxProps): JSX.Element;
function H3(props: BoxProps): JSX.Element;
function H4(props: BoxProps): JSX.Element;
function H5(props: BoxProps): JSX.Element;
function H6(props: BoxProps): JSX.Element;

interface TextProps extends BoxProps {
  leading?: keyof Theme['typography']['leading'];
  size?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
  tracking?: keyof Theme['typography']['tracking'];
  color?: keyof Theme['palette'];
  weight?: keyof Theme['typography']['fontWeight'];
}

Typography Components

Theme System

Complete theming system with React Context, design tokens, and responsive utilities.

// Theme context provider
function ThemeProvider(props: { theme: Theme; children: ReactNode }): JSX.Element;

// Hook to access current theme
function useTheme(): Theme;

// React context for theme
const ThemeContext: React.Context<{ theme: Theme }>;

// Default theme object
const theme: Theme;

// Responsive utilities hook
function useMediaQuery(): {
  mq: (styles: any) => any;
  minBreak: (key: keyof Theme['breakpoints']) => string;
  maxBreak: (key: keyof Theme['breakpoints']) => string;
};

Theme System

Core Application Wrapper

Application wrapper component that provides global styles and normalization.

// Root application wrapper with global styles
function Core(props: CoreProps): JSX.Element;

interface CoreProps {
  children: ReactNode;
  includeNormalize?: boolean;
  optimizeLegibility?: boolean;
}

Core Application Wrapper

Utility Components and Functions

Accessibility helpers, utility functions, and additional UI components.

// Screen reader only content component
function VisuallyHidden(props: { children?: ReactNode; as?: ElementType }): JSX.Element;

// Visual separator component  
function Divider(props: DividerProps): JSX.Element;

// Centering layout component
function Center(props: CenterProps): JSX.Element;

// Link component with theme integration
function Link(props: { as?: ElementType }): JSX.Element;

// Polymorphic component helper
function forwardRefWithAs<DefaultElementType extends ElementType, BaseProps>(
  render: (props: BaseProps & { as?: ElementType }, ref: React.Ref<any>) => ReactNode
): CompWithAsProp<BaseProps, DefaultElementType>;

interface DividerProps extends MarginProps {
  color?: ResponsiveProp<keyof Theme['palette']>;
  orientation?: 'horizontal' | 'vertical';
}

interface CenterProps extends BoxProps {
  fillView?: boolean;
}

Utility Components

Emotion Integration

Re-exported Emotion functions for consistent CSS-in-JS usage across the ecosystem.

// CSS styling function
function css(template: TemplateStringsArray, ...args: any[]): SerializedStyles;

// JSX pragma for emotion
function jsx(type: any, props: any, ...children: any[]): any;

// CSS keyframes for animations
function keyframes(template: TemplateStringsArray, ...args: any[]): Keyframes;

// Global CSS styles component
function Global(props: { styles: any }): JSX.Element;

// Render prop for dynamic class names
function ClassNames(props: { children: (cx: any) => ReactNode }): JSX.Element;

// CSS normalization styles for consistent cross-browser rendering
const normalize: SerializedStyles;

Emotion Integration

State Management Hooks

Utilities for managing component state in controlled/uncontrolled patterns.

// Hook for controlled/uncontrolled component patterns
function useManagedState<V, E = ChangeEvent>(
  controlledValue: V | undefined,
  defaultValue: V,
  onChange: ManagedChangeHandler<V, E> | undefined
): [V, ManagedChangeHandler<V, E>];

type ManagedChangeHandler<V = string, E = ChangeEvent> = (value: V, event: E) => void;

// Utility functions
function devWarning(condition: boolean, message: string): void;
function makeId(...args: (string | number | null | undefined)[]): string;
function useId(idFromProps?: string | null): string | undefined;

State Management

Types

// Main theme type derived from default theme
type Theme = typeof theme;

// Responsive prop type for breakpoint-aware values
type ResponsiveProp<T> = T | readonly (T | null)[];

// Component prop types
type ColorProps = {
  background?: ResponsiveProp<keyof Theme['palette']>;
  foreground?: ResponsiveProp<keyof Theme['palette']>;
};

type RadiiProps = {
  rounding?: ResponsiveProp<keyof Theme['radii']>;
  roundingBottom?: ResponsiveProp<keyof Theme['radii']>;
  roundingLeft?: ResponsiveProp<keyof Theme['radii']>;
  roundingRight?: ResponsiveProp<keyof Theme['radii']>;
  roundingTop?: ResponsiveProp<keyof Theme['radii']>;
};

type MarginProps = {
  margin?: ResponsiveProp<keyof Theme['spacing']>;
  marginTop?: ResponsiveProp<keyof Theme['spacing']>;
  marginRight?: ResponsiveProp<keyof Theme['spacing']>;
  marginBottom?: ResponsiveProp<keyof Theme['spacing']>;
  marginLeft?: ResponsiveProp<keyof Theme['spacing']>;
  marginY?: ResponsiveProp<keyof Theme['spacing']>;
  marginX?: ResponsiveProp<keyof Theme['spacing']>;
};

type PaddingProps = {
  padding?: ResponsiveProp<keyof Theme['spacing']>;
  paddingTop?: ResponsiveProp<keyof Theme['spacing']>;
  paddingRight?: ResponsiveProp<keyof Theme['spacing']>;
  paddingBottom?: ResponsiveProp<keyof Theme['spacing']>;
  paddingLeft?: ResponsiveProp<keyof Theme['spacing']>;
  paddingY?: ResponsiveProp<keyof Theme['spacing']>;
  paddingX?: ResponsiveProp<keyof Theme['spacing']>;
};

type BoxProps = ColorProps & RadiiProps & MarginProps & PaddingProps & {
  textAlign?: ResponsiveProp<'left' | 'right' | 'center' | 'justify' | 'start' | 'end'>;
  height?: ResponsiveProp<string | number>;
  width?: ResponsiveProp<string | number>;
};
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@keystone-ui/core@5.0.x
Publish Source
CLI
Badge
tessl/npm-keystone-ui--core badge