0.1.259 • Published 18 days ago

apphouse v0.1.259

Weekly downloads
-
License
MIT
Repository
github
Last release
18 days ago

Apphouse

** THIS LIBRARY IS UNDER DEVELOPMENT - API MIGHT CHANGE SIGNIFICANTLY **

  • A highly efficient method for creating a React + Typescript application.
  • Comprehensive reusable components that can look completely different based on a configurable theme
  • Models that support observability for faster and more efficient rendering

Why Apphouse?

  • Apphouse simplifies the pain of writing themes, forms, popups, routes, feedback, etc., providing a comprehensive solution for all these essential components that you always need. Although it can handle a lot, using Apphouse is incredibly easy and user-friendly.

Usage

Via CLI

With our cli app, you can effortlessly start an entire project in just two simple commands.

Note: You must use node v18.0.0 nvm use v18.0.0

npm install -g apphouse-cli
apphouse-cli your-project-name

Manually

npm install apphouse

Sample App

Initialize Apphouse

import React from 'react';
import ReactDOM from 'react-dom/client';
import { initApphouse } from 'apphouse';

const store = initApphouse(routes);

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <ApphouseApp store={store} />
);

Setting Up Routes

To define specific routes for your app, simple create a route object and use it when initializing apphouse

import React from 'react';
import ReactDOM from 'react-dom/client';
import { initApphouse, ApphouseApp } from 'apphouse';

const routes: Route[] = [
  {
    path: '/',
    title: 'Home',
    component: () => {
      return <App />;
    }
  }
];

const store = initApphouse(routes);

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <ApphouseApp store={store} />
);

Setting Up Restricted Routes

To define a restricted route, simply wrap it with RequiresFirebaseAuthentication component. We currently only support firebase simple email & password authentication.

import React from 'react';
import ReactDOM from 'react-dom/client';
import { initApphouse } from 'apphouse';

const routes: Route[] = [
  {
    path: '/',
    title: 'Home',
    component: () => {
      return <App />;
    }
  },
  {
    path: '/account',
    title: 'Account',
    component: (
      <RequiresFirebaseAuthentication showSignInButton showSignOutButton>
        <MySecretContentComponent />
      </RequiresFirebaseAuthentication>
    )
  }
];

const firebaseConfig = {
  apiKey: 'yourApiKey',
  authDomain: 'yourAuthDomain',
  projectId: 'yourProjectId',
  storageBucket: 'yourStorageBucket',
  messagingSenderId: 'yourMessagingSenderId',
  appId: 'yourAppId',
  measurementId: 'yourmeasurementId'
};

const appStore = new AppStoreWithUser(firebaseConfig);
const store = initApphouse(
  Routes,
  appStore as IStoreWithBase<AppStoreWithUser>
);

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <ApphouseApp store={store} />
);

Setting Up Routes With Params

We also accept parametrized routing

import React from 'react';
import ReactDOM from 'react-dom/client';
import { initApphouse } from 'apphouse';

const routes: Route[] = [
  {
    path: '/account/:id',
    title: 'My Account',
    component: ({ id }) => <MyComponentForPage1 id={id} />
  }
];

const store = initApphouse(routes);

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <ApphouseApp store={store} />
);

Extending Theme

You can change your app theme simply by extending apphouse's default theme or making your own from scratch

Extending Theme

const BRAND_COLOR = 'rgb(236, 0, 138)';
const customTheme: ApphouseTheme = extendTheme(DarkTheme, {
  colors: {
    brand: BRAND_COLOR
  },
  tokens: {
    radius: {
      default: '30px'
    }
  },
  styles: {
    input: {
      default: {
        borderRadius: '30px'
      }
    }
  }
});
const store = initApphouse(routes);

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <ApphouseApp store={store} theme={customTheme} />
);

Check out our demo app to get a sneak peek at how you can easily customize your theme. Simply visit this link to explore and experiment with various customization options.

Personalized Not Found Page

Every time a user tries to access a route that doesn't exist, they will be redirected to this page. By default Apphouse offers a standard 404 Not Found page. If you want to overwrite this page with your own 404 page add your 404 substitute when defining the route

const routes: Route[] = [
  {
    path: '/404',
    title: 'Not Found',
    component: () => <MyCustom404Page />
  }
];

Handling Alerts

Anywhere inside of your components you can fire the feedback by calling the alert method

const { alert } = useApphouse();

alert({
  type: FeedbackType.success,
  message: 'Success message',
  duration: 3000
});

Handling Forms

Apphouse provides a simple and efficient way to handle very complex forms. To create a form, simply create a new instance of Form class and pass in the form configuration object.

const form = new Form({
  id: "signUp", // you will use this id to retrieve this form later
  title: 'Sign Up!',
  fields: {
    // initial value for this field can be set here
    name: "",
    // initial value for this field can be set here
    email: ""
  },
  validations: {
    email: (value: string) => {
      // do email validation
      return true if valid, return false if invalid
    }
  },
  options: {},  // no options
  required: ['name', 'email'], // both name and email fields are required

Updating Values

To update form field value simply:

form.setValue('name', 'updatedName');

Accessing form values

const name = form.getValue('name');

Get all form data

To get current form data

const formData = form.data;

For more detailed information on how to use the form view the form documentation

Using the ApphouseForm Component

If you just want to create a simple form, you can use the ApphouseForm component.

Below is an example that showcases the usage of ApphouseForm component along with the Popup component to create a prompt that asks the user to enter a file name.

import { ApphouseForm } from '../components/Form/ApphouseForm';
import { Popup } from '../components/popup/Popup';

/**
 * A prompt that will ask the user to enter a file name
 */
export const PromptFilename = ApphouseComponent((props: { onConfirm }) => {
  const { onConfirm } = props;

  const onSubmission = (formData) => {
    onConfirm(formData.filename);
  };
  return (
    <Popup
      id="PromptFilenamePopup"
      title="Save theme as"
      closeOnClickOutside
      hideFooterActions
      showCloseButton
      width="320px"
      gutters={4}
    >
      <ApphouseForm
        id="PromptFilenameForm"
        fields={[
          {
            id: 'filename',
            label: 'File name',
            type: 'text',
            required: true,
            value: undefined,
            styleOverwrites: {
              container: {
                width: '100%'
              },
              input: {
                width: '100%'
              }
            }
          }
        ]}
        submitButtonLabel="Save"
        onSubmission={onSubmission}
      />
    </Popup>
  );
});

Registering Shortcuts

Apphouse can handle shortcuts anywhere in the app. You can register a global shortcut by:

app.shortcuts.register('escape', callback);

Similarly you can unregister a global shortcut by

app.shortcuts.unregister('escape', callback);

If you want to register multiple shortcuts you can do so by using the registerAppShortcuts method

app.shortcuts.registerAppShortcuts([
  {
    combo: 'cmd+s',
    action: () => {
      console.log('save');
    }
  }
]);

Shortcut in Text fields

By default all keyboard events will not fire if you are inside of a textarea, input, or select to prevent undesirable things from happening.

Partial Views

A partial view refers to any view within the application that does not take up the entire page or is considered "transient" within a flow. Examples of partial views include modals, tabs, popups, pickers, and so on.

There are several scenarios in which you would want to set a partial view:

  1. When you want to provide the option for users to quickly close the view by using the 'escape' shortcut.
  2. When you want to enable users to access the view via a specific URL.
  3. When you want to allow the opening and closing of the view through a trigger located in a completely different place from where the view will be displayed.
// set up route in routes and set openPartial: true

  {
    path: '/demo/:themeEditor',
    title: 'Theme Editor Drawer Open',
    openPartial: true,
    component: () => {
      return <Demo />;
    }
  }
export const DrawerDemo = observer(() => {
  const { app } = useApphouse();
  const { view } = app;

  return (
    <React.Fragment>
      <div>
        <Button
          onClick={() => {
            // this will open the drawer below and also update the url
            // to be demo/themeEditor
            view.setView('themeEditor', true);
          }}
        >
          Edit theme
        </Button>
      </div>

      <Drawer
        id="theme-editor"
        open={view.getViewStatus('themeEditor')}
        onClose={() => view.setView('themeEditor', false)}
      >
        drawer content
      </Drawer>
    </React.Fragment>
  );
});
0.1.259

18 days ago

0.1.257

2 months ago

0.1.256

2 months ago

0.1.258

2 months ago

0.1.255

2 months ago

0.1.254

2 months ago

0.1.253

2 months ago

0.1.252

2 months ago

0.1.251

2 months ago

0.1.250

2 months ago

0.1.239

9 months ago

0.1.118

10 months ago

0.1.238

9 months ago

0.1.117

10 months ago

0.1.119

10 months ago

0.1.235

10 months ago

0.1.234

10 months ago

0.1.113

10 months ago

0.1.237

10 months ago

0.1.116

10 months ago

0.1.236

10 months ago

0.1.115

10 months ago

0.1.231

10 months ago

0.1.110

10 months ago

0.1.230

10 months ago

0.1.233

10 months ago

0.1.112

10 months ago

0.1.232

10 months ago

0.1.111

10 months ago

0.1.129

10 months ago

0.1.249

9 months ago

0.1.128

10 months ago

0.1.246

9 months ago

0.1.245

9 months ago

0.1.248

9 months ago

0.1.127

10 months ago

0.1.247

9 months ago

0.1.126

10 months ago

0.1.242

9 months ago

0.1.121

10 months ago

0.1.241

9 months ago

0.1.120

10 months ago

0.1.244

9 months ago

0.1.243

9 months ago

0.1.122

10 months ago

0.1.240

9 months ago

0.1.139

10 months ago

0.1.136

10 months ago

0.1.135

10 months ago

0.1.138

10 months ago

0.1.137

10 months ago

0.1.132

10 months ago

0.1.131

10 months ago

0.1.134

10 months ago

0.1.133

10 months ago

0.1.130

10 months ago

0.1.147

10 months ago

0.1.149

10 months ago

0.1.148

10 months ago

0.1.143

10 months ago

0.1.142

10 months ago

0.1.145

10 months ago

0.1.144

10 months ago

0.1.141

10 months ago

0.1.140

10 months ago

0.1.206

10 months ago

0.1.205

10 months ago

0.1.208

10 months ago

0.1.207

10 months ago

0.1.202

10 months ago

0.1.201

10 months ago

0.1.204

10 months ago

0.1.203

10 months ago

0.1.200

10 months ago

0.1.209

10 months ago

0.1.217

10 months ago

0.1.216

10 months ago

0.1.219

10 months ago

0.1.218

10 months ago

0.1.213

10 months ago

0.1.212

10 months ago

0.1.215

10 months ago

0.1.211

10 months ago

0.1.210

10 months ago

0.1.228

10 months ago

0.1.227

10 months ago

0.1.109

10 months ago

0.1.229

10 months ago

0.1.108

10 months ago

0.1.224

10 months ago

0.1.223

10 months ago

0.1.226

10 months ago

0.1.225

10 months ago

0.1.220

10 months ago

0.1.222

10 months ago

0.1.221

10 months ago

0.1.190

10 months ago

0.1.192

10 months ago

0.1.191

10 months ago

0.1.198

10 months ago

0.1.197

10 months ago

0.1.199

10 months ago

0.1.194

10 months ago

0.1.193

10 months ago

0.1.196

10 months ago

0.1.195

10 months ago

0.1.158

10 months ago

0.1.157

10 months ago

0.1.159

10 months ago

0.1.154

10 months ago

0.1.153

10 months ago

0.1.156

10 months ago

0.1.155

10 months ago

0.1.150

10 months ago

0.1.152

10 months ago

0.1.151

10 months ago

0.1.169

10 months ago

0.1.168

10 months ago

0.1.165

10 months ago

0.1.164

10 months ago

0.1.167

10 months ago

0.1.166

10 months ago

0.1.161

10 months ago

0.1.160

10 months ago

0.1.163

10 months ago

0.1.162

10 months ago

0.1.170

10 months ago

0.1.179

10 months ago

0.1.176

10 months ago

0.1.175

10 months ago

0.1.178

10 months ago

0.1.177

10 months ago

0.1.172

10 months ago

0.1.171

10 months ago

0.1.174

10 months ago

0.1.173

10 months ago

0.1.181

10 months ago

0.1.180

10 months ago

0.1.187

10 months ago

0.1.186

10 months ago

0.1.189

10 months ago

0.1.188

10 months ago

0.1.183

10 months ago

0.1.182

10 months ago

0.1.185

10 months ago

0.1.184

10 months ago

0.1.107

10 months ago

0.1.106

10 months ago

0.1.103

10 months ago

0.1.105

10 months ago

0.1.104

10 months ago

0.1.96

10 months ago

0.1.97

10 months ago

0.1.98

10 months ago

0.1.99

10 months ago

0.1.90

10 months ago

0.1.91

10 months ago

0.1.92

10 months ago

0.1.93

10 months ago

0.1.94

10 months ago

0.1.89

10 months ago

0.1.102

10 months ago

0.1.101

10 months ago

0.1.100

10 months ago

0.1.85

10 months ago

0.1.86

10 months ago

0.1.87

10 months ago

0.1.88

10 months ago

0.1.80

10 months ago

0.1.81

10 months ago

0.1.82

10 months ago

0.1.83

10 months ago

0.1.84

10 months ago

0.1.74

10 months ago

0.1.75

10 months ago

0.1.76

10 months ago

0.1.77

10 months ago

0.1.78

10 months ago

0.1.79

10 months ago

0.1.71

10 months ago

0.1.72

10 months ago

0.1.73

10 months ago

0.1.70

10 months ago

0.1.69

10 months ago

0.1.68

10 months ago

0.1.67

10 months ago

0.1.66

10 months ago

0.1.65

10 months ago

0.1.64

11 months ago

0.1.63

11 months ago

0.1.62

11 months ago

0.1.61

11 months ago

0.1.60

11 months ago

0.1.59

11 months ago

0.1.58

11 months ago

0.1.57

11 months ago

0.1.56

11 months ago

0.1.52

11 months ago

0.1.51

11 months ago

0.1.50

11 months ago

0.1.49

11 months ago

0.1.48

11 months ago

0.1.47

11 months ago

0.1.46

11 months ago

0.1.45

11 months ago

0.1.44

11 months ago

0.1.43

11 months ago

0.1.42

11 months ago

0.1.41

11 months ago

0.1.39

11 months ago

0.1.38

11 months ago

0.1.36

11 months ago

0.1.35

11 months ago

0.1.34

11 months ago

0.1.33

11 months ago

0.1.32

11 months ago

0.1.31

11 months ago

0.1.30

11 months ago

0.1.29

11 months ago

0.1.28

11 months ago

0.1.26

11 months ago

0.1.25

11 months ago

0.1.24

11 months ago

0.1.23

11 months ago

0.1.22

11 months ago

0.1.21

11 months ago

0.1.20

11 months ago

0.1.19

11 months ago

0.1.18

11 months ago

0.1.17

11 months ago

0.1.16

11 months ago

0.1.15

11 months ago

0.1.14

11 months ago

0.1.13

11 months ago

0.1.12

11 months ago

0.1.11

11 months ago

0.1.10

11 months ago

0.1.9

11 months ago

0.1.8

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago